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
Code:
#include <iostream> #include <algorithm> #include <stdio.h> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <ctype.h>using namespace std;int a[50000];int main() {int n;while(scanf("%d",&n)!=EOF){int i,j,carry,len=1,t;memset(a,0,sizeof(a));a[0]=1;for(i=2;i<=n;i++){for(carry=0,j=0;j<len;j++){t=a[j]*i+carry;a[j]=t%10;carry=t/10;}while(carry){a[j++]=carry%10;carry/=10;len++;}}for(j=len-1;j>=0;j--)printf("%d",a[j]);printf("\n");}return 0; }