标签:
Description
Input
Output
Sample Input
Sample Output
#include <stdio.h>
#include <stdlib.h>
#define N 33
void num (int n, int r, char a[]);
int main()
{
char a[N];
int n,r;
while (scanf ("%d%d", &n, &r)!=EOF)
{
num(n, r, a);
}
return 0;
}
void num (int n, int r, char a[])
{
int i = 0;
if (n<0)
{
n = -n;
printf("-");
}
while (n>0)
{
a[i]=n%r;
if (a[i]>=10)
a[i]=‘A‘+a[i]-10;
n = n/r;
i++;
}
a[i] = ‘\0‘;
for ( i = i-1; i>=0; i--)
{
if(a[i]>=‘A‘ && a[i]<=‘Z‘)
printf("%c", a[i]);
else
printf ("%d", a[i]);
}
printf ("\n");
}
标签:
原文地址:http://www.cnblogs.com/yishilin/p/4231854.html