C Programming Code Examples C > Conversions Code Examples Program to convert decimal number to binary Program to convert decimal number to binary #include <stdio.h> #include <math.h> long long convertDecimalToBinary(int n); int main() { int n; printf("Enter a decimal number: "); scanf("%d", &n); printf("%d in decimal = %lld in binary", n, convertDecimalToBinary(n)); return 0; } long long convertDecimalToBinary(int n) { long long binaryNumber = 0; int remainder, j = 1, step = 1; while (n!=0) { remainder = n%2; printf("Step %d: %d/2, Remainder = %d, Quotient = %d\n", step++, n, remainder, n/2); n /= 2; binaryNumber += remainder*j; j *= 10; } return binaryNumber; }