1057N的阶乘

基准时间限制: 1 秒 空间限制: 131072 KB 分值: 0 难度:基础题
收藏
关注
输入N求N的阶乘的准确值。
Input
输入N(1 <= N <= 10000)
Output
输出N的阶乘
Input示例
5
Output示例
120
 
    

#include <stdio.h>
#include <string.h>
const int maxn=3000;
int f[maxn];
int main()
{
    int i=0,j=0,n=0;
    scanf("%d",&n);
    memset(f,0,sizeof(f));
    f[0]=1;
    for(i=2;i<=n;i++)
    {
        int c=0;
        for(j=0;j<maxn;j++)
        {
            int s=f[i]*i+c;
            f[j]=s%10;
            c=s/10;
        }
    }
    for(j=maxn-1;j>=0;j--)if(f[j]) break;
    for(i=j;i>=0;i--)printf("%d",f[i]);
    printf("\n");
    return 0;
}

发布了29 篇原创文章 · 获赞 3 · 访问量 3198

猜你喜欢

转载自blog.csdn.net/qq_38436175/article/details/76223837