返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int ans(int);
  5. int main()
  6. {
  7.     int x ,;
  8.     cout<<"請輸入欲推算的費氏數列項次: ";
  9.     cin>>x;
  10.     cout<<x<<"費氏數列中, 第"<<x<<"個數的值為:"<<ans(x)<<endl;
  11.     system("pause");   
  12.     return 0;
  13. }
  14. int ans(int x)
  15. {
  16.      if(x<=1)
  17.      return x;
  18.      else
  19.      return ans(x-1)+ans(x-2);
  20.              }
複製代碼

TOP

返回列表