3104. 整数转换为字符串

Easy字符串递归函数

时间限制:2000 ms

内存限制:256 MiB

题面

使用 递归方法 定义函数 i2a, 将 1 个非负整数转换成字符串。

要求:不调用库函数 sprintf、itoa。

Note:这个函数的功能与非标准库函数 itoa 相类似。

//********** Specification of i2a **********
void i2a(char p[],int n);
/* PreCondition:
n is a non-negative integer, p is a pointer to a buffer
PostCondition:
put string representation of n in a buffer pointed by p,and return p
*/

只需按要求写出函数定义,并使用给定的测试程序测试你所定义函数的正确性。不要改动测试程序。测试正确后,将测试程序和函数定义一起提交。

/***************************************************************/
/*                                                             */
/*  DON'T MODIFY main function ANYWAY!                         */
/*                                                             */
/***************************************************************/
#include <stdio.h>
//********** Specification of i2a **********
void i2a(char p[],int n)
/* PreCondition:
n is a non-negative integer, p is a pointer to a buffer
PostCondition:
put string representation of n in a buffer pointed by p
*/
{
	//TODO: your function definition
}
/***************************************************************/
int main()
{
	int n; char s[20];
	scanf("%d",&n);
	//********** i2a is called here ********************
	i2a(s,n);
	printf("%s\n",s);
	//**************************************************
	return 0;
}