4.11 N!
来源:互联网 发布:c语言求数组最小值 编辑:程序博客网 时间:2024/06/06 03:08
Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
输入
One N in one line, process to the end of file.
输出
For each N, output N! in one line.
样例输入
样例输出
#include <stdio.h>
int main()
{
int m;
while(scanf("%d",&m)!=EOF)
{
int t[10000];
t[0]=1;
int a=0;
for(int n=1;n<=m;n++)
{
int c=0;
for(int i=0;i<=a;++i)
{
t[i] = t[i]*n + c;
c = t[i] / 100000;
t[i] %= 100000;
}
if(c!=0) // 如果有进位
{
a++;
t[a] = c;
}
}
printf("%d",t[a]);
for(int i=a-1;i>=0;i--)printf("%05d",t[i]);
printf("\n");
}
return 0;
}
0 0