Last active
April 6, 2016 13:23
-
-
Save shahril96/5b2aa327b43e64a62ab427178e86736f to your computer and use it in GitHub Desktop.
Convert base-10 integer to any base-N (base 2 until base 10) presentation
This file contains 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 int2bin(int n, int base) { | |
if(n > 0) { | |
int2bin(n / base, base); | |
printf("%d ", n % base); | |
} | |
} | |
int main() { | |
int2bin(999, 2); | |
puts(""); | |
int2bin(3103, 10); | |
puts(""); | |
int2bin(10000, 3); | |
puts(""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment