求阶乘

#include 

using namespace std;

int jiecheng(int a) {
    if(a == 0)
        return 1;
    else if (a == 1 || a == 2)
        return a;
    else return (a * jiecheng(a - 1));
}

int main()
{
    int n;
    cin >> n;
    while(n--) {
        int a, r;
        cin >> a;
        r = jiecheng(a);
        cout << r << endl;
    }
    return 0;
}

你可能感兴趣的:(求阶乘)