Skip to content

Instantly share code, notes, and snippets.

@tomer
Last active August 6, 2016 23:05
Show Gist options
  • Save tomer/7108ab176109e439f8d6ccce2b1dac6a to your computer and use it in GitHub Desktop.
Save tomer/7108ab176109e439f8d6ccce2b1dac6a to your computer and use it in GitHub Desktop.
Decimal number to binary
#include<stdio.h>
void dec2bin(int number) {
if (number == 0) return;
dec2bin(number/2);
printf ("%d", number % 2);
}
void main() {
int number;
printf("Please enter number: ");
scanf("%d", &number);
printf("The result is: ");
dec2bin(number);
printf("\n");
}
$ gcc dec2bin.c -o dec2bin
$ ./dec2bin
Please enter number: 973
The result is: 1111001101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment