#45091: C++ (AC) for迴圈 真是暴力的一題


1121228@stu.wghs.tp.edu.tw (你知道我是誰嗎!!??)

學校 : 臺北市私立薇閣高級中學
編號 : 266561
來源 : [60.248.154.139]
最後登入時間 :
2025-01-24 13:06:02
d487. Order's computation process -- 學姊 | From: [60.248.154.139] | 發表日期 : 2025-01-06 14:06

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, s;
    while (cin >> n) {
        if (n == 0 || n == 1) { //如果是0或1直接輸出n! = 1 = 1即可
            cout << n << "! = 1 = 1" << endl;
        } else {
            s = n;
            cout << n << "! = ";
            for (int i = n; i > 1; i--) {
                cout << i << " * ";
                if (n != i) {
                    s = s * i;
                }
            }
            cout << "1 = " << s << endl;
        }
    }
    return 0;
}

 
ZeroJudge Forum