C Programming Code Examples C > Conversions Code Examples Program to Convert Decimal Number to Binary Number Program to Convert Decimal Number to Binary Number The programs takes decimal number (entered by user) as input and converts it into a binary number using the function decimalToBinary(). #include <stdio.h> #include <math.h> long decimalToBinary(int decimalnumber) { long binarynumber = 0; int rem, temp = 1; while (decimalnumber!=0) { rem = decimalnumber%2; decimalnumber = decimalnumber / 2; binarynumber = binarynumber + rem*temp; temp = temp * 10; } return binarynumber; } int main() { int decimalnumber; printf("Enter a Decimal Number: "); scanf("%d", &decimalnumber); printf("Equivalent Binary Number is: %ld", decimalToBinary(decimalnumber)); return 0; }