Problem Description

Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!

Input

One N in one line, process to the end of file.

Output

For each N, output N! in one line.

Sample Input

1
2
3

Sample Output

1
2
6

题目大意:

大数阶乘,0<=n<=10000;求n的阶乘。

c++

#include <iostream>
#include<cstring>
using namespace std;
int a[1600100];
int main()
{
    int b,c,d,e,f,g;
    while(cin>>b)
    {
        memset(a,0,sizeof(a));
        a[0]=1;g=0;     //a数组中每一位用来存放一位数,g用来记录位数
        for(c=1;c<=b;c++)
        {
            for(d=0;d<=g;d++)    //a数组中每一位都与c相乘
            {
                a[d]=a[d]*c;
            }
            for(d=0;d<=g;d++)
            {
                if(a[d]>=10)    //a数组中数值>=10时进位
                {
                    a[d+1]=a[d]/10+a[d+1];
                    a[d]=a[d]%10;

                }
            }
            if(a[g+1]!=0)  //判断g的下一位是否为0
                g++;
            while(a[g]>=10)  //使a数组中每一位只存放一位数
            {
                a[g+1]=a[g]/10;a[g]=a[g]%10;g++;
            }
        }
        for(c=g;c>=0;c--)
        {
            cout<<a[c];
        }
        cout<<endl;
    }
    return 0;
}