# c program to convert decimal number to binary number

list of c programs below: c program to convert decimal number to binary using functions, c program to convert decimal number to binary without functions

To convert decimal number to binary is divide the decimal  number with 2 at each step and take remainders.

eg To convert decimal number 10 to binary

2  | 2
2  | 1 – 0
| 0 – 1

here 1’s &  0’s are are remainders
Now combine all remainders serially from down to up  i.e  10  This is binary number of  2 (decimal )

Convert decimal number to binary program logic: Enter decimal number n, divide n by 2 ( since binary ) and save remainder in array and quotient in n repeat until n is greater than zero.

## Write a C program to convert decimal number to binary number using while loop

Write a C program to convert decimal number to binary using while loop

#include <stdio.h>
void main()
{
int i=0,n,b;
printf(“\n OUTPUT: C program for converting decimal number to binary number”);
printf(“\nEnter decimal number: \n”;
scanf(“%d”,&n);
while (n>0)
{
b[i]=n%2;
n=n/2;
i++;
}
printf(“\nBinary is: “);
while(i>0)
{
printf(b[i]);
i–;
}
}

OUTPUT: C program for converting decimal number to binary number
Enter decimal number:2
Binary is: 10

## write a program to convert decimal number to binary number using for loop

Write a C program to convert decimal number to binary number using for loop

#include <stdio.h>
void main()
{
int i=0,n,a;
printf(“\n OUTPUT: C program for converting decimal number to binary number”);
printf(“\nEnter decimal number: \n”;
scanf(“%d”,&n);
for(;n>0;n=/2 )
{
a[i]=n%2;
i++;
}
printf(“\nBinary is: “);
while(i>0)
{
printf(a[i]);
i–;
}
}

OUTPUT:

OUTPUT: C program for converting decimal number to binary number
Enter decimal number:3
Binary is: 11

## Write a C program to convert decimal number to binary number using functions

Write a C program to convert decimal number to binary number using functions

#include <stdio.h>
void main()
{
int i=0,n,b;
printf(“\n OUTPUT: C program for converting decimal number to binary number”);
printf(“\n  Enter decimal number: \n”);
scanf(“%d\n”,&n);
b=Dec_To_Bin(n);
printf(“The Binary value of decimal number %d  is:  \n”, n);
while(b[i]!=’\0′)
{
i++;
}
while(i>=0)
{
printf(“%d”, b[i]);
i–;
}
}

int[] Dec_To_Bin(int num)
{
int i=0, Bin;
while (num>0)
{
Bin[i]=num%2;
num=num/2;
i++;
}
return Bin;

}

OUTPUT:

OUTPUT: C program for converting decimal number to binary number
Enter decimal number:2
Binary is: 10

Why do we need to convert decimal number to binary?

The term binary has is the base for design of any logical circuit. TO represent a number or an alphabet or an operation or a screen element in any electronic circuit binary representation is used. A human understandable decimal number is used or stored in any electronic circuit in binary format