C Programming

C Program to Convert Decimal to Binary

Write a c program to convert decimal number to binary number.

/*Program to convert decimal to binary*/
#include<stdio.h>
#include<conio.h>
int bin(int x);
void main()
{
int x,binary;
printf("Enter Decimal Number:");
scanf("%d",&x);
binary=bin(x);
printf("The Binary number is %d",binary);
getch();
}
int bin(int x)
{
int q,r;
if(x==0)
return;
q=x/2;
r=x%2;
bin(q);
printf("%d",r);
}
Back to top button