1 #define _CRT_SECURE_NO_WARNINGS 2 #include <iostream> 3 4 using namespace std; 5 //用递归求某一项的阶乘的值 6 int fun(int i)//求第i项的值 7 { 8 if (1 == i) 9 return 1; 10 return fun(i - 1) * i;//返回某一项阶乘的值 11 } 12 //用递归求某些项阶乘的和 13 int fun1(int i)//求前i项阶乘的和 14 { 15 if (1 == i) 16 return 1; 17 return fun1(i - 1) + fun(i);//返回某些阶乘和的值 18 } 19 void test01() 20 { 21 cout << "输出1到20的阶乘的和fun1(20):" << fun1(20) << endl; 22 } 23 24 int main(void) 25 { 26 test01(); 27 system("pause"); 28 return 0; 29 }
标签:return,递归,int,C++,fun,阶乘,fun1,法求 From: https://www.cnblogs.com/guang123/p/16729386.html