943,458 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 6608
  • C++ RSS
Dec 1st, 2004
0

octal conversion

Expand Post »
sir, ihave a doubt on converting a inputed decimel number to a octal number
will u help me?
Similar Threads
Reputation Points: 11
Solved Threads: 0
Newbie Poster
gowswan is offline Offline
2 posts
since Nov 2004
Dec 1st, 2004
0

Re: octal conversion

you mean you want to print an octal representation of a decimal number?
Check out your language reference for itoa.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Dec 1st, 2004
-1

Re: octal conversion

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();


}
Reputation Points: 10
Solved Threads: 1
Light Poster
varunrathi is offline Offline
41 posts
since Aug 2004
Dec 1st, 2004
0

Re: octal conversion

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
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Dec 1st, 2004
0

Re: octal conversion

>#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.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Can Someone Tell me why my program does not run
Next Thread in C++ Forum Timeline: problems w/ program involving structures and arrays





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC