N!

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

Author

JGShining(极光炫影)

#include<iostream>
#include<string.h>


using namespace std;
int a[100000];
int main()int 
{
int i,j;
int n;
while(cin>>n)
{
   memset(a,0,sizeof(a));
   a[0]=1;
   int s,count=1;
   for(i=1;i<=n;i++)
   {
   s=0;
    for(j=0;j<count;j++)
    {
     a[j]=a[j]*i+s;
     s=a[j]/10;
     a[j]=a[j]%10;
    }
    while(s)
    {
     a[count]=s%10;
     s=s/10;
     count++;
    }
   }
   for(i=count-1;i>=0;i--)
    cout<<a[i];
   cout<<endl;
}
return 0;
}

posted @ 2014-04-07 13:57  冷夏的博客园  阅读(215)  评论(0编辑  收藏  举报