题解 | #阶乘#

阶乘

https://www.nowcoder.com/practice/4b8f5815c7cd40ab851c24fc5de70fa4

#include <iostream>
using namespace std;
typedef long long LL;//应对超过32位的n!
LL jiechen(int n){
    LL mul=1;
    for(int i=n;i>=1;i--){
        mul*=i;
    }
    return mul;
}
int main() {
    int m;
    cin>>m;
    int arr[m];
    LL ans=0;
    for(int i=0;i<m;i++){
        cin>>arr[i];
    }
    for(int i=0;i<m;i++){
        ans=jiechen(arr[i]);
        cout<<ans<<endl;
}
return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

06-05 19:46
已编辑
武汉大学 后端
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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