返回列表 發帖
  1. #include<iostream>
  2. using namespace std;
  3. int calcu(int);
  4. int main()
  5. {
  6.      int x;
  7.      cout<<"請輸入階層運算的值(譬如5!便輸入5):";
  8.      cin>>x;
  9.      cout<<x<<"階層運算的結果值為"<<calcu(x)<<endl;
  10.      system("pause");
  11.      return 0;
  12. }
  13. int calcu(int x)
  14. {
  15.      if(x==1)
  16.      {
  17.          return x;
  18.      }else
  19.      {
  20.          return x*calcu(x-1);
  21.      }
  22. }
複製代碼

TOP

返回列表