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
大数阶乘!!
#include <iostream>
using namespace std;
int a[55555];
int main()
{
int n,i,j;
while(scanf("%d",&n)!=EOF)
{
memset(a,0,sizeof(a));
if(n==0||n==1)
{
printf("1\n");
continue;
}
int l=1;
a[0]=1;
for(i=2;i<=n;i++)
{
for(j=0;j<l;j++)
a[j]*=i;
for(j=0;j<l;j++)
{
if(a[j]>9)
{
a[j+1]+=a[j]/10;
a[j]%=10;
if(j==l-1)
l++;
}
}
}
for(i=l-1;i>=0;i--)
printf("%d",a[i]);
printf("\n");
}
return 0;
}