- #include <iostream>
- using std::cout;
- using std::cin;
- using std::endl;
- int fun(int n)
- {
- if(n==1)
- {
- return 1;
- }
- else
- {
- while(n>1)
- {
- return fun(n-1)*n;
- }
- }
- }
- void main()
- {
- int n;
- cout<<"please input the number"<<endl;
- cin>>n;
- cout<<"the result is"<<fun(n)<<endl;
- }
c++实现N阶的递归算法
最新推荐文章于 2023-01-15 10:49:45 发布