问题描述 :
给你一个整数N(0 ≤ N ≤ 10000),你的任务是计算并输出 N!
输入说明 :
输入多行,每行一个N。
输出说明 :
对于每个输入N,在一行中输出N!
行首与行尾为空格,两组输出之间无空行。
输入范例 :
2
1
100
输出范例 :
2
1
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int n,i,j,carry,flag,s;
while(scanf("%d",&n)!=EOF){
flag=1;
int temp[10000]={1};
for(i=1;i<=n;i++){
carry=0;
for(j=0;j<flag;j++){
s=temp[j]*i+carry;
temp[j]=s%10;
carry=s/10;
}
while(carry!=0){
temp[flag]=carry%10;
++flag;
carry/=10;
}
}
for(i=flag-1;i>=0;i--){
if(i!=0){
printf("%d",temp[i]);
}else{
printf("%d\n",temp[i]);
}
}
}
return 0;
}