题解 | #To Fill or Not to Fill#

n的阶乘

http://www.nowcoder.com/practice/97be22ee50b14cccad2787998ca628c8

13!会超出int的表示上限,可以改成long long类型。

#include <iostream>

using namespace std;

//例题8.1 n的阶乘
long long jiecheng(int x){
    if(x==1)return 1;
    return x*jiecheng(x-1);
}
int main()
{
    int x;
    cin>>x;
    cout<<jiecheng(x)<<endl;
}

全部评论

相关推荐

评论
6
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务