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