N!
http://acm.hdu.edu.cn/showproblem.php?pid=1042
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 37977 Accepted Submission(s): 10555
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> #include<string.h> int num[10005]; int main(){ int n; while(scanf("%d",&n)!=EOF){ memset(num,0,sizeof(num)); int i,j,tmp; num[0]=1; for(i=1;i<=n;i++){ tmp=0; for(j=0;j<10005;j++){ tmp+=num[j]*i; num[j]=tmp%10000; tmp/=10000; } } for(i=10004;i>=0;i--) if(num[i]!=0) break; printf("%d",num[i--]); for(j=i;j>=0;j--) printf("%04d",num[j]); printf("\n"); } return 0; }