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<stdio.h>
int a[40000];
int main()
{
int n,i,j,x;
while(scanf("%d",&n)!=EOF)
{
a[0]=1;a[1]=1;
if(n==0||n==1) {printf("1\n");continue;}
for(i=2;i<=n;i++)
{
x=0;
for(j=1;j<=a[0];j++)
{
a[j]*=i;
a[j]+=x;
x=a[j]/10;
a[j]=a[j]%10;
}
while(x)
{
a[j]=x%10;
a[0]=j;
x=x/10;
j++;
}
}
for(i=a[0];i>=1;i--) printf("%d",a[i]);
printf("\n");
}
return 0;
}