用递归法将一个整数n转换成字符串,例如输入483,应输出字符串“483”。n的位数不确定,可以是任意位数的整数。 **输入提示:"\n输入整数:" **输入格式:"%d" **输出提示:"\n输出是:" **输出转换的字符串 程序的运行示例如下: 输入整数:345 输出是:345
#include <stdio.h>
void convert(int n)
{
int i;
if ((i = n / 10) != 0)
{
convert(i);
}
putchar(n % 10 + '0');
}
int main()
{
int number;
printf("\n输入整数:");
scanf("%d", &number);
printf("\n输出是:");
if (number < 0)
{
putchar('-');
number = -number;
}
convert(number);
return 0;
}