题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1042
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>
#define N 35700
#include<cstring>
using namespace std;
int a[N];
int main( )
{
int n,i,j,c,s;
while(scanf("%d",&n)!=EOF){
memset(a,0,sizeof(a));
a[0]=1;
for(j=2;j<=n;j++)
{
for( c=0,i=0;i<N;i++)
{
s=a[i]*j+c;
a[i]=s%10;
c=s/10;
}
}
for(i=N-1;i>=0;i--)
if(a[i])break;
//cout<<i<<endl;
for(j=i;j>=0;j--)
cout<<a[j];
cout<<endl;
}
return 0;
}