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> #include<string.h> #define N 36000 int a[N]; int main() {int n,i,s,c,j; while(scanf("%d",&n)!=EOF) {memset(a,0,sizeof(a)); a[0]=1; for(i=2;i<=n;i++) {c=0; for(j=0;j<n;j++) /*这个循环的意义就是:把个位赋给a[0],十位赋给a[1].... */ {s=a[j]*i+c; /*c的意义就是需要进位的那个数 */ a[j]=s%10; c=s/10; } } for(i=N-1;i>=0;i--) {if(a[i]) break; } for(;i>=0;i--) printf("%d",a[i]); printf("\n"); } return 0; }