Last active
August 6, 2016 23:05
-
-
Save tomer/7108ab176109e439f8d6ccce2b1dac6a to your computer and use it in GitHub Desktop.
Decimal number to binary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ 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