Created
January 16, 2015 08:46
-
-
Save kenornotes/4a86218174a08ccf8eda to your computer and use it in GitHub Desktop.
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> | |
//讀入兩值,將val以base進位印出 | |
//若base > 10,以A, B, C....,代表10, 11, 12.... | |
void print(int val, int base){ | |
int tmp[100], digit = 0; | |
while(val != 0) { | |
tmp[digit++] = val % base; | |
val = val / base; | |
} | |
for(; digit > 0; digit--) { | |
int tmpnum = tmp[digit - 1]; | |
if(tmpnum >= 10) | |
printf("%c",65+(tmpnum - 10)); | |
else | |
printf("%d", tmpnum); | |
} | |
} | |
int main() { | |
int value,base; | |
scanf("%d %d", &value, &base); | |
print(value, base); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment