用递归方法求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);
}

 

posted @ 2018-12-01 21:53  裏表異体  阅读(4313)  评论(0编辑  收藏  举报