递归三要素

递归三要素:

  1.定义函数功能

  2.特殊条件(结束条件)

  3.表达式

 

递归——阶乘

#include <iostream>
using namespace std;
int b(int n){
    if(n<=2){
        return n;
    }
    return n*b(n-1);
}
int main(){
    int a;
    cin>>a;
    cout<<b(a)<<endl;
    
    return 0;
}

 

posted @ 2024-06-08 09:27  郭立恒  阅读(87)  评论(0)    收藏  举报