很简单的一道递归题
2024-07-17 08:49:38
发布于:河北
23阅读
0回复
0点赞
经典递归类型题
以下下为递归代码
#include<bits/stdc++.h>
using namespace std;
int klo(int n){//阶乘函数
if(n1){//当n等于1时直接返回自身
return n;
}else if(n0){//题目的特殊条件
return 1;
}else{
return n*klo(n-1);//递归
}
}
int main(){
int n;
cin>>n;
int m=klo(n);//调用函数
cout<<m<<endl;输出
}
这里空空如也
有帮助,赞一个