76. C Program to Convert Decimal number Into Binary Number.
How does this program work?
- This Program is used to convert Decimal number into Binary number using C program.
- Decimal number means it is a simple integers 0 to 9.
- Binary decimal contains 0 or 1 numbers.
- This below code explains how to convert a decimal integer into binary number.
Here is the code
#include <stdio.h>
int main()
{
int num,cnt,i;
int binary[32];
printf("Enter decimal number: ");
scanf("%d",&num);
cnt=0; /*initialize index to zero*/
while(num>0)
{
binary[cnt]=num%2;
num=num/2;
cnt++;
}
/*print value in reverse order*/
printf("Binary value is: ");
for(i=(cnt-1); i>=0;i--)
printf("%d",binary[i]);
return 0;
}