| | |
octal conversion
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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();
}
#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();
}
![]() |
Similar Threads
- Enquiries about Bitwise operators (C++)
- Decimal system to Binary, Octal and Hexadecimal system Conversion.. (C)
- Octal to Decimal number conversion program (C)
Other Threads in the C++ Forum
- Previous Thread: Can Someone Tell me why my program does not run
- Next Thread: problems w/ program involving structures and arrays
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int integer java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






