#include<iostream>
#include<string>
//#include<fstream>
//#include<math.h>
using namespace std;
int show(int n,int i,int s);
int main()
{
int n;
int i=1,total=1;
cout << "你想计算几的阶乘:";
cin >> n;
int sum = show(n, i, total);
cout << "the reason: " <<sum << endl;
cin.get();
cin.get();
return 0;
}
int show(int n,int i,int s)
{
if (n == 0 || n == 1)
{
return s;
}
if (n > 1 && i < n+1)
{
s = s*i;
++i;
show(n, i,s);
}
else
{
return s;
}
}
递归函数普通例子
最新推荐文章于 2024-07-31 11:35:18 发布