Problem Description

給定一個 n 值,請計算出 n! 的結果    

The Input

輸入一個整數 n

The Output

輸出 n! 結果,結果不大於 263

Sample Input

0
1
5

Sample Output

1
1
120

-----* Problem from【ZeroJudge, an Online Judge System For Beginners

My Answer

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  #include<iostream>
using namespace std;
long long int f(int n);
int main(void)
{
  int n;
  while(cin>>n){
    cout<<f(n)<<endl;
  }
}

long long int f(int n)
{
  if(n==0) return 1;
  else return n*(f(n-1));
}
 

 


arrow
arrow
    全站熱搜

    兔老大 發表在 痞客邦 留言(0) 人氣()