题目描述:
输入一个正整数N,输出N的阶乘。
输入:
正整数N(0<=N<=1000)
输出:
输入可能包括多组数据,对于每一组输入数据,输出N的阶乘
样例输入:
4
5
15
样例输出:
24
120
1307674368000
代码转自:http://blog.csdn.net/gaotong2055/
#include <stdio.h> int big[1001][800],len[1001],BASE=10000; int i,j,tmp,up,n; void print(int n){ printf("%d",big[n][len[n]-1]); for(i=len[n]-2; i >= 0; i--)printf("%04d",big[n][i]); printf("\n"); } int main(){ big[0][0] = big[1][0] = len[0] = len[1] = 1; for(i=2; i<=1000; i++){ up = 0; for(j=0; j<len[i-1]; j++){ tmp = up + i * big[i-1][j]; up = tmp / BASE; tmp = tmp % BASE; big[i][j] = tmp; } if(up > 0){ big[i][j] = up;len[i] = j+1; } else len[i] = j; } while(~scanf("%d",&n))print(n); return 0; }