/* CONVERT DECIMAL TO BINARY,OCTAL,HEXADECIMAL NUMBERS */
#include<stdio.h>
#include<conio.h>
main()
{
int n,b,i,a[10];
clrscr();
printf("\n Enter decimal value:");
scanf("%d",&n);
printf("\n Enter base value (2,8,16):");
scanf("%d",&b);
for(i=0;n>0;i++)
{
a[i]=n%b;
n=n/b;
}
printf("\n After converting the values are:");
for(i=i-1;i>=0;i--)
{
if(b==2)
printf("%d",a[i]);
else if(b==8)
printf("%d",a[i]);
else
printf("%d",a[i]);
}
getch();
}
No comments:
Post a Comment