llllmz

导航

KY17 n的阶乘C++

递归一下。

#include<iostream>
using namespace std;

long compute(int n){
    if(n==1) return 1;
    return n* compute(n-1);
}

int main(){
    int n;
    while( cin >> n){
        cout << compute(n) <<'\n';
    }
    return 0;
}

结果:

posted on 2024-01-22 15:58  神奇的萝卜丝  阅读(14)  评论(0)    收藏  举报