/* * Program to compute binary from decimal (using recursion). * * Input: Positive decimal integer N. * * Output: Binary equivalent of N. */ #include /* Convert N to binary and print (does not print "\n" at the end) */ void dec_to_bin(int N) { int q; int r; if (N > 0) { r = N % 2; q = N / 2; dec_to_bin(q); printf("%d", r); } } /* Main program */ int main(void) { int N; int r; int q; printf("enter decimal integer (must not be <= 0)\n"); if (scanf("%d", &N) != 1) { printf("Not a number\n"); } else if (N < 0) { printf("The number must be positive\n"); } else { dec_to_bin(N); printf("\n"); } return 0; }