1. 程式人生 > >88-大數階乘的模板

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;
}