Factorial
Time Limit: 2000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
Homelesser hates mathematics. He cannot even do addition and subtraction, not to mention computing factorial. He asks Cainiao2hao for help. Cainiao2hao is always busy solving more difficult problems. And now, please help Homelesser to compute factorial. If you cannot do it well, Cainiao2hao will think you are as fool as Homelesser.
输入
The first line contains only one integer T (T is about 10) indicates the number of test cases. For each case there are one integer n (0 ≤ n ≤ 10).
输出
One line for each case specifying the factorial of n.
示例输入
2 4 3
示例输出
24 6
提示
来源
2014年山东省第五届ACM大学生程序设计竞赛
示例程序
#include<stdio.h>
int main()
{
int i,j,n,m,k,t,f1,f2;
scanf("%d",&n);
for(i=0;i<n;i++)
{
f1=1;
scanf("%d",&m);
if(m==0)
printf("%d\n",f1);
if(m>=1)
{
for(j=1;j<=m;j++)
{
f2=f1*j;
f1=f2;
}
printf("%d\n",f2);
}
}
}