Aug 28, 2015

program to convert decimal to any base

/* program to convert decimal to any base */
#include<iostream.h>
#include<conio.h>
void main()
{
int no,m,a[10],base,i=0,l;
clrscr();
cout<<"Enter the decimal no ";
cin>>no;
cout<<"Enter the base ";
cin>>base;
cout<<"\n The output";
while(no>0)
{
m=no%base;
a[i]=m;
++i;
no=no/base;
}
--i;
for(l=i;l>=0;--l)
if(a[l]<=9)
cout<<a[l];
else if(a[l]==10)
cout<<"A";
else if(a[l]==11)
cout<<"B";
else if(a[l]==12)
cout<<"C";
else if(a[l]==13)
cout<<"D";
else if(a[l]==14)
cout<<"E";
else
cout<<"F";
getch();
}

No comments:

Post a Comment