To convert a decimal number to binary number in C


Levels of difficulty: / perform operation:

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

C Program

#include <stdio.h>
#include <conio.h>
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[i]);
	getch();
}


Output