zufeoj_阶乘

题目链接:http://acm.ocrosoft.com/problem.php?cid=1172&pid=13


题目描述

输入n,请用递归的方式求n的阶乘。

输入

多组测试数据,读入到文件尾结束。

每组测试数据输入一个n (1<=n<=8)。

输出

每组测试数据,输出n的阶乘。

样例输入

1
2
3

样例输出

1
2
6


#include<bits/stdc++.h>
using namespace std;
int f(int n){
    if(n==1||n==0){
        return 1;
    }else{
        return n*f(n-1);
    }
}
int main(){
    int n;
    while(cin>>n){
        cout<<f(n)<<endl;
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/m0_37345402/article/details/80753401