octal conversion

Reply

Join Date: Nov 2004
Posts: 2
Reputation: gowswan is an unknown quantity at this point 
Solved Threads: 0
gowswan gowswan is offline Offline
Newbie Poster

octal conversion

 
0
  #1
Dec 1st, 2004
sir, ihave a doubt on converting a inputed decimel number to a octal number
will u help me?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: octal conversion

 
0
  #2
Dec 1st, 2004
you mean you want to print an octal representation of a decimal number?
Check out your language reference for itoa.
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 41
Reputation: varunrathi is an unknown quantity at this point 
Solved Threads: 1
varunrathi's Avatar
varunrathi varunrathi is offline Offline
Light Poster

Re: octal conversion

 
-1
  #3
Dec 1st, 2004
Here`s the code to convert a decimel number in any desired base

#include<iostream.h>
#include<conio.h>
#include<stdio.h>


void main()
{
clrscr();
int d,b=1,r,a,q,c = 0,s;
char n[100];

cout<<"enter the no.:";
cin>>d;
cout<<"\nenter base :";
cin>>b;

while(d>0)
{
q = d/b;
r = d%b;
d = q;

if(r>=10)
{
n[c] = 55 + r;
c++;
}
else
{
n[c] = 48 + r;
c++;
}
}
n[c] = '\0';

cout<<"\nthe no. in base "<<b<<" is : ";
for(int i = c-1;i>=0;i--)
{
cout<<n[i];
}

getch();


}
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: octal conversion

 
0
  #4
Dec 1st, 2004
don't give people complete programs, it stops them from thinking for themselves...

Or if you do include some subtle logic errors that they'll have to solve to make it work.

And if you do give sample code make it proper code.
void main() is an abomination, <iostream.h> etc. are deprecated
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,306
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 227
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: octal conversion

 
0
  #5
Dec 1st, 2004
>#include<iostream.h>
>#include<conio.h>

Nonstandard headers.

>#include<stdio.h>

Unused header.

>void main()

Incorrect.

>clrscr();

Unnecessary and a nonstandard function.

> n[c] = 55 + r;
> n[c] = 48 + r;

ASCII hacks.

>getch();

Nonstandard function.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC