| | |
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();
}
#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 |
api array based binary bitmap c++ c/c++ char class classes code coding compaitibility compile console conversion count delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error factorial file floatingpoint forms fstream function functions game givemetehcodez graph guessing gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker loop looping loops map math matrix maze memory multiple net news node oop output payment pointer practice problem program programming project projectassignmenthelp protection python random rank read recursion reference rpg skills string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets






