C Program To Convert Decimal To Binary

In this program we will going to convert decimal to binary using while loop. The code for the program is given below.

C Program To Convert Decimal To Binary

#include <stdio.h>
#include <math.h>
int main()
{
 int num, j, i=0, bin[10];
printf("Enter a decimal number: ");
 scanf("%d", &num);
 while(num>0)
{
bin[i]=num%2;
num=num/2;
i++;
 }
for(j=i-1;j>=0;j--)
{
 printf("%d",bin[j]);
}
return 0;
}

Output

Enter a decimal number: 24
11000

Read: C program to convert GCD of the given 2 numbers


If You Like This Page Then Make Sure To Follow Us on Facebook, G News and Subscribe Our YouTube Channel. We will provide you updates daily.
Shares
facebook sharing button Share
twitter sharing button Tweet
whatsapp sharing button Share
telegram sharing button Share
pinterest sharing button Pin

Leave a Comment