2017年9月17日 星期日

[C_MM21-易] 算階乘(C++)

[C_MM21-易] 算階乘


  1. #include <iostream>  
  2. using namespace std;  
  3.   
  4. int main() {  
  5.     int n;  
  6.     long long factorial = 1;  
  7.     while(cin >> n)  
  8.     {  
  9.         if(0 < n && n < 20)  
  10.         {  
  11.             for(int i = 1; i <= n; i++)  
  12.             {  
  13.                 factorial   = factorial * i;  
  14.             }  
  15.             cout << factorial << endl;  
  16.             factorial = 1;  
  17.         }  
  18.     }  
  19.     return 0;  
  20. }  




沒有留言:

張貼留言