Decimal to binary conversion in C by R4R Team

Decimal number:
range : 0 to 9

Binary numnber :
range : 0 to 1

Decimal to binary conversion:

Example-
Decimal number is 8
Binary number is 1000

Decimal number is 23
Binary number is 10111

program-

#include< stdio.h>
int main() {
int n,num=0;
printf("Enter decimal number\n");
scanf("%d",&n);
while(n)
{
num=num*10+n%2;
n=n/2;
}
printf("It's binary is %d",num);
}


output-

Enter decimal number
7
It's binary is 111

Enter decimal number
10
It's binary is 1010

-In this program, we take an input of decimal number and find its binary equivalent.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!