C Program to Convert Decimal Number to Binary Number

Program


#include<stdio.h>
#include<conio.h>

int main()
{
	 long int decimal, binary=0, rem, num, base=1;
	 clrscr();
	 printf("Enter decimal number: ");
	 scanf("%ld", &decimal);
	 num = decimal;
	 
	 while(num !=0 )
	 {
	  rem = num%2;
	  binary = binary + base * rem;
	  base = base*10;
	  num = num/2;
	 }
	 
	 printf("Decimal (%ld) = Binary (%ld)", decimal, binary);
	 getch();
	 return(0);
}

Output of above program :

Enter decimal number: 727 ↲
Decimal (727) = Binary (1011010111)

Note: ↲ indicates enter is pressed.