代码:
#include<stdio.h>
char b[]="0123456789ABCDEF" ;
int main()
{
int n,k;
while(scanf("%d%d",&n,&k)!=EOF)
{
char a[50]={' '};
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("
");
}
return 0;
}