Home Forums C Programming base conversion Re: base conversion

#3264
yeswanth
Participant

A program to convert a decimal number to its equivalent binary number.

#include 
#include
void main()
{
unsigned long dec;
int a[25],c=0,i;
clrscr();
printf("nENTER A DECIMAL NUMBER: ");
scanf("%lu",&dec);
printf("n%lu IN BINARY FORMAT: ",dec);
while(dec>0)
{
a[c]=dec%2;
dec=dec/2;
c++;
}
for(i=c-1;i>=0;i--)
printf("%d",a);
getch();
}