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 m=10000; struct bignum{ int s[20001];//存放结果 int l;//数组的长度 }a; bignum operator*(bignum a,int b)//a=a*b { int i; for(i=0;i<a.l;i++) a.s[i]*=b;//a的各位数乘b for(i=0;i<a.l;i++) { a.s[i+1]+=a.s[i]/m; a.s[i]%=m; } while(a.s[a.l]!=0)//处理a的最高位 { a.s[a.l+1]+=a.s[a.l]/m; a.s[a.l]=a.s[a.l]%m; a.l++; } while(a.s[a.l-1]==0) a.l--; return a; } void print(bignum a) { printf("%d",a.s[a.l-1]); for(int i=a.l-2;i>=0;i--) printf("%04d",a.s[i]); printf(" "); } int main() { int n; while(scanf("%d",&n)!=EOF) { int i; memset(a.s,0,sizeof(a.s)); a.s[0]=1;a.l=1; for(i=1;i<=n;i++) { a=a*i; } print(a); } return 0; }