海底城市的画:用c语言递归调用如何解这道题?—求助!!!

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 23:54:27
写一个函数,用递归法将一个整数n转换成字符串.例如输入483,应输出字符串"483",n的位数不确定,可以是任意位数的整数.
void convert(int n)
{

}
main()
{int n;
printf("Please input number:");
scanf("%d",&n);
printf("\nconverted is :");
if(n<0)
{putchar('-');
n=-n;
convert(n);
}
}

#include <stdio.h>
#include<stdlib.h>

void convert(int n)
{
char buffer[65];
itoa( n, buffer, 10 );
printf("%s\n",buffer);
}
void main()
{
int n;
printf("Please input number:");
scanf("%d",&n);
printf("\nconverted is :");
if(n<0)
{putchar('-');
n=-n;
}

convert(n);// 这个地方是我提出来的,稍作修改
}

vc6.0测试通过

不懂C语言只懂C#
static void Main()
{
int n=null;
Console.WriteLine("Please input number");
try
{
n=Int32.Prase(Console.Read());
Console.WriteLine(n);
}
catch()
{
}

}

其实用函数:sprintf就可以了。
可以直接将各种类型的数据转换成字符串。