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 main(){ int a[101000],n,l; while(~scanf("%d",&n)){ memset(a,sizeof(a)); a[0] =1; l=1; for(int i=1;i<=n;i++){ int s = 0,j; for( j=0;j<l||s;j++){ int z= a[j]*i+s; a[j] = z%10; s = z/10; } l=j; //printf("%d\n",l); } for(int j = l-1;j>=0;j--)printf("%d",a[j]); printf("\n"); } }