数字转字符

Description

下面程序中“/ ***** N ***** /”的下一行中有错误,请改正(注意:不得加行、减行、加句、减句,否则后果自负)。 该程序功能:用递归法将一个六位整数n转换成字符串,例如输入123456,应输出字符串"123456"。 #include void itoa(long i,char *s) { if(i==0) return; /****** 1 ******/ *s = '1'+i%10; itoa(i/10,s-1); } void main() { long n; char str[7]=""; scanf("%ld",&n); /****** 2 ******/ itoa(n,str+6); printf("%s",str); }

Input

输入一个六位正整数n。

Output

把该整数转换成对应字符串。

Sample Input

123456

Sample Output

123456

#include<stdio.h>
void itoa(long i,char *s)
{
if(i==0)
return;
*s = '0'+i%10;
itoa(i/10,s-1);
}

int main()
{
long n;
char str[7]="";
scanf("%ld",&n);
itoa(n,str+5);
printf("%s",str);
}

原文地址:https://www.cnblogs.com/zhouweibaba/p/10147316.html