Skip to content

Instantly share code, notes, and snippets.

@kenornotes
Created January 16, 2015 08:46
Show Gist options
  • Save kenornotes/4a86218174a08ccf8eda to your computer and use it in GitHub Desktop.
Save kenornotes/4a86218174a08ccf8eda to your computer and use it in GitHub Desktop.
#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