#38160: c++遞迴參考


judgeking001 (adking)

School : No School
ID : 195281
IP address : [180.218.90.201]
Last Login :
2024-05-10 17:18:58
a111. 12149 - Feynman -- UVa12149 | From: [220.143.112.181] | Post Date : 2023-10-30 00:58

#include <bits/stdc++.h>
using namespace std;

int Feynman(int n)
{
    return n == 1 ? 1 : (pow(n, 2) + Feynman(n - 1));
}

int main()
{
    int n;
    while (cin >> n)
    {
        if (n == 0)
            break;
        cout << Feynman(n) << endl;
    }
    return 0;
}
 
ZeroJudge Forum