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
#include<iostream>
#include<iomanip>
using namespace std;
int n,i,k,l;
int main()
{
while(cin>>n)
{ int a[80000]={0};
a[0]=1;l=0;
int m,s=1;
for(i=1;i<=n;i++)
{
for(m=1;m<=s;m++)
a[m-1]*=i;
for(m=0;m<s;m++)
{ if(a[m]>9999&&m==s-1) {s++;}
while(a[m]>9999)
{
a[m+1]+=a[m]/10000;
a[m]=a[m]%10000;
}
} }
for(k=s-1;k>=0;k--)
{if(l==0)
{cout<<a[k];l=1;}
else
{cout<<setfill('0')<<setw(4)<<a[k];}}
cout<<endl;}
return 0; }