问题及代码:
/*作者:贾如杉、
问题
输入一串整数,输出该整数的逆序数
输入
一个int型整数
输出
转换后的整数
*/
#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;
}
printf("%d",n%10);
inverted(n/10);
return;
}
运行结果
知识点总结
自定义函数的练习,提高逻辑能力
学习心得
简单的自定义函数练习,巩固知识