How to write a C Program to convert given decimal number into binary number in C Programming Language ?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],n,i,j=0,rem;
clrscr();
printf("\nEnter the Decimal Number: ");
scanf("%d",&n);
while(n!=1)
{
rem=n%2;
printf("\n%d",rem);
a[j]=rem;
n=n/2;
printf("\n%d%d",a[j],n);
j++;
}
a[j]=1;
printf("\nBinary Number is: ");
for(i=j;i>=0;i--)
printf("%d",a[i]);
getch();
}
//OUTPUT:
//Enter the Decimal Number: 12
6 0
3 0
1 1
1 1
//Binary Number is: 1100