问题:递归方法实现逆序
#include <stdio.h>
void inverted(int); /*函数声明*/
int main()
{
int n; /*需要逆序的整数*/
scanf("%d",&n);
inverted(n); /*调用逆序函数*/
return 0;
}
void inverted(int n)
{
if(n<10) /*当数字只剩一位的时候,即第一位数,输出,变为末位,返回*/
{
printf("%d",n);
return;
}
else
{
printf("%d",n%10);
inverted(n/10);
return;
}
return;
}
知识点总结:
要注意输出数字的位置和函数返回的位置。