2014年山东省第五届ACM--Factorial (求阶乘)

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大学生程序设计竞赛


水题求阶乘。。。

AC代码:

#include <stdio.h>  
int main()  
{  
    int a[15];  
    a[0]=1;  
    a[1]=1;  
    int T;  
    int n,i,j;  
      
    for(i=2;i<=10;i++)  
        a[i]=a[i-1]*i;  
      
    scanf("%d",&T);  
    while(T--)  
    {  
        scanf("%d",&n);  
        if(T==0)  
        printf("%d",a[n]);  
        else  
        printf("%d\n",a[n]);  
    }  
      
    return 0;  
} 


你可能感兴趣的:(2014年山东省第五届ACM--Factorial (求阶乘))