输入基数b(2<=b<=10)和正整数n(十进制),输出n的b进制表示。
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int result[100];
void fun(int b, int n)
{
int i = 0;
while (n)
{
result[i] = n%b;
n /= b;
i++;
}
}
int main()
{
int b, n, i;
char firstFound = 0;
memset(result, 0, sizeof(result));
scanf("%d,%d", &b, &n);
fun(b, n);
for (i = 99; i >= 0; i--)
{
if (result[i] > 0 && !firstFound)
{
firstFound = 1;
}
if (firstFound)
{
printf("%d", result[i]);
}
}
printf("\n");
return 0;
}