88-大数阶乘的模板

https://blog.csdn.net/huxiansheng__/article/details/80052081

#include<iostream>
#include<cstdio>
#include<cstring>
int s[100000]={0};//数组用来储存结果。
using namespace std;
int main()
{
    int n,sum=1,i,j,temp=0,h=0,l;
    s[0]=1;//初始化为1。
    l=1;
    scanf("%d",&n);
    for(i=2;i<=n;i++)//1就不用在运行了。
    {
        for(j=1;j<=l;j++)//这里,你想不通就无法理解这个代码。
        {                                 1  5  ——————>i
            temp=s[j-1]*i+h;           1  2  1  ——————>s中储存的数据。
            s[j-1]=temp%10;           -----------     
            h=temp/10;                    1  5 
        }                              3  0     
        while(h)                    1  5        
        {                          ---------------//想不通的看这个图,自己理解一下,因为不知该怎么讲。
            l++;                    1  8  1  5
            s[l-1]=h%10;
            h/=10;
        }
    }
    for(i=l-1;i>=0;i--)
    {
        printf("%d",s[i]);
    }
    cout<<endl;
}

  

猜你喜欢

转载自www.cnblogs.com/zhumengdexiaobai/p/10172035.html
今日推荐