#include
char *change(int n,int k, char s[]) {
int i = 0,len,t,num = 0;
if(k < 2 || k > 36) return NULL;
while(n) {
t = n % k;
if(t > 9) s[i] = t - 10 + 'A';
else s[i] = t + '0';
n /= k;
++i;
}
s[i] = '\0';
len = i;
for(i = 0; i < len/2; ++i) {
t = s[i];
s[i] = s[len - 1 - i];
s[len - 1 - i] = t;
}
return s;
}
int main() {
int k,num;
char s[33];
printf("num newbase:");
while(scanf("%d%d",&num,&k) == 2) {
if(change(num,k,s)) printf("%s\n",s);
else printf("不能转换到 %d 进制。\n",k);
printf("num newbase(q to quit):");
}
return 0;
}
这个函数标准库里有,不需要写。你搜下 itoa()函数;