1.正序存放
void numpal(char *p,int n)
{
if(n==0)
*p=’\0’;
else
{
numpal(p,n/10);
p=p+strlen§;
*p=n%10+‘0’;
*(p+1)=’\0’;
}
}
2.逆序存放
void reverse(char *p,int n)
{
*p=n%10+‘0’;
if(n!=0)
reverse(p+1,n/10);
else
*p=’\0’;
}
设计递归函数,将正整型数转换为字符串。字符数组和正整数在main中输入,并在main中输出。
最新推荐文章于 2022-12-08 21:05:09 发布