代码:
#include<stdio.h>
char b[]="0123456789ABCDEF" ;
int main()
{
int n,k;
while(scanf("%d%d",&n,&k)!=EOF)
{
char a[50]={‘\0‘};
int i=0,ok;
ok=(n>=0)?0:n=-n,1;
while(n)
{
a[i++]=b[n%k];
n=n/k;
}
if(ok)printf("-");
for(;i>0;i--)
printf("%c",a[i-1]);
printf("\n");
}
return 0;
}
原文:http://www.cnblogs.com/weiyikang/p/3870055.html