Example & Tutorial understanding programming in easy ways.

Write a program to convert the decimal number to its binary equivalent

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");
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.




Read More →