【題解】ZeroJudge d487: Order’s computation process

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=d487

#include <iostream>
using namespace std;

int func(int n){
    if (n == 1){
        cout << " 1";
        return 1;
    }else{
        cout << " " << n << " *";
        return n * func(n-1);
    }
}
int main(){
    int n, ans;
    while (cin >> n){
        if (n == 0){
            cout << "0! = 1 = 1\n";
        }
        else{
            cout << n << "! =";
            ans = func(n);
            cout << " = " << ans << "\n";
        }
    }
}
分享本文 Share with friends