C Programming Code Examples C > For Loops and While Loops Code Examples C program to convert Decimal to Binary number system C program to convert Decimal to Binary number system Write a C program to input decimal number from user and convert to binary number system. How to convert from decimal number to binary number system in C program. Decimal number system Decimal number system is a base 10 number system. Decimal number system uses only 10 symbols to represent all number i.e. 0123456789 Binary number system Binary number system is a base 2 number system. Binary number system uses only 2 symbols to represent all numbers i.e. 0 and 1 Algorithm to convert from decimal to binary Algorithm Decimal to Binary conversion begin: read (decimal); binary = 0; place = 1; rem = 0; while (decimal > 0) do begin rem = decimal % 2; binary = (rem * place) + binary; place = place * 10; decimal = decimal / 2; end write('Binary = ' binary) end #include <stdio.h> int main() { long long decimal, tempDecimal, binary; int rem, place = 1; binary = 0; /* Input decimal number from user */ printf("Enter any decimal number: "); scanf("%lld", &decimal); tempDecimal = decimal; /* Decimal to binary conversion */ while(tempDecimal > 0) { rem = tempDecimal % 2; binary = (rem * place) + binary; tempDecimal /= 2; place *= 10; } printf("Decimal number = %lld\n", decimal); printf("Binary number = %lld", binary); return 0; }