将整数转换成字符串
编写函数 void myitoa(int n, char *str),将整数转换成字符串 // 编写函数 void myitoa(int n, char *str),将整数转换成字符串#include <stdio.h>
int myitoa(int n, char *str); //自定义函数声明
int main()
{
char str; //定义一个数组
int m;
printf("Enter some numbers:");
scanf("%d", &m); //输入一串数字
myitoa(m, str); //调用函数
printf("%s\n", str); //输出字符串
return 0;
}
int myitoa(int n, char *str) //自定义函数
{
int i;
if (!n)
return 0;
i = myitoa(n / 10, str);
str = '0' + n % 10;
str = 0;
return i + 1;
}
页:
[1]