N!
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 53983 Accepted Submission(s): 15289
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> #define MAX 50000 int f[MAX]; int main() { int i,j,n,c,s; int flag; while(scanf("%d",&n)!=EOF){ flag=1; memset(f,0,sizeof(f)); f[0]=1; for(i=1;i<=n;i++){ c=0; for(j=0;j<flag;j++){ s=f[j]*i+c; f[j]=s%10; c=s/10; } while(c) //记录进位 { f[flag++]=c%10; c/=10; } } for(j=MAX-1;j>=0;j--) if(f[j]) break; for(i=j;i>=0;i--) printf("%d",f[i]); printf("\n"); } return 0; }