C program to convert decimal to binary

Posted on 03rd July 2013

This is a simple C program to convert a decimal number to binary.

The program divides the decimal number repeatedly by 2 while storing the remainder in an array.

The final binary value is obtained by printing the array in reverse order.

For example if the user inputs 12, the program converts it to 1100

Program Source Code

/* **********************************************
 * Program to convert Decimal to Binary		*

#include <stdio.h>
#include <conio.h>

int main() 
 int num, bin_num[100], dec_num, i,j;

 // Read an integer number
 printf("Enter an integer number\n");
 dec_num = num;

 // Convert Decimal to Binary
 while (dec_num) {
	bin_num[i] = dec_num % 2;
	dec_num = dec_num / 2;
 // Print Binary Number
 printf("The binary value of %d is ",num);
 for (j=i-1; j>=0; j-- ) {

 // Wait for key press

return 0;

Program Output

Enter an integer number
The binary value of 200 is 11001000

Post a comment


sulav | February 16, 2016 10:36 AM |

you can use following program if u r a beginner in c language...... this is the most possible simplest way to convert decimal number to binary #include #include void main() { int i=0,b=1,n; printf("enter a number"); scanf("%d",&n); while(n) //when n becomes zero loop inside "while" stops or you can use while(n!=0) or while(n>0) and so on...... { i=