用递归方法求n的阶乘

代码:

#include<iostream>
using namespace std;
int fact(int n);
int main()
{
    int n;
    loop:
    cin >> n;
    cout << fact(n);
    goto loop;
}
int fact(int n)
{
    if (n == 0)       //递归终止条件
    {
        return 1;
    }
    return n * fact(n - 1);
}

猜你喜欢

转载自www.cnblogs.com/urahyou/p/10051212.html
今日推荐