/*Copyright(c)2014,烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作者:满星辰
*完成日期:2014年 11月 13日
*版本号:v1.0
*
*问题描述:
*程序输入:
*程序输出:
*/
#include <iostream>
using namespace std;
void f(int);
int main()
{
int i=1234;
f(i);
return 0;
}
void f(int n)
{
if(n==0)
return;
else
{
f(n/10);
cout<<n%10;
return;
}
}
预期:1234
实际:1234
学习心得:
依次输出该数的最高位~最低位
#include <iostream>
using namespace std;
int sub(int);
int main()
{
int i=5;
cout<<sub(i)<<endl;
}
int sub(int n)
{
int a;
if (n==1)
return 1;
a=n+sub(n-1);
return a;
}
预期:15
实际:15
学习心得:
从1~5的递归累加
本文详细探讨了递归函数的工作原理,通过具体案例展示了如何利用递归实现数值累加,并深入分析了其背后的逻辑流程。同时,文章还介绍了函数调用的基本概念及其在编程中的应用,为读者提供了全面的技术指导。

被折叠的 条评论
为什么被折叠?



