A - N! Problem

Your task is to caculate N! .

Input
For each test case : Line 1 : An integer N.(0 <= N <= 10) Process to the end of file.

Output
For each test case : Line 1 : Output the answer of N!.

Sample Input

   3

Sample Output

   6

運用遞歸

int main(void)
{
    double func(double);
    int n;
    while(scanf("%d", &n) == 1)
    {
        printf("%.0f\n", func(n));
    }
}
double func(double m)
{
    if(m == 1 || m == 0)
    {
        return 1;
    }
    else
    {
        return m * func(m - 1);
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章