954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

octal conversion

sir, ihave a doubt on converting a inputed decimel number to a octal number
will u help me?

gowswan
Newbie Poster
2 posts since Nov 2004
Reputation Points: 11
Solved Threads: 0
 

you mean you want to print an octal representation of a decimal number?
Check out your language reference for itoa.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Here`s the code to convert a decimel number in any desired base

#include
#include
#include


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 "<=0;i--)
{
cout<

varunrathi
Light Poster
41 posts since Aug 2004
Reputation Points: 10
Solved Threads: 1
 

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, etc. are deprecated

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

>#include
>#include

Nonstandard headers.

>#include

Unused header.

>void main()

Incorrect.

>clrscr();

Unnecessary and a nonstandard function.

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

ASCII hacks.

>getch();

Nonstandard function.

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You