返回列表 發帖
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int f(int x)
  4. {
  5.     if(x<2)
  6.         return x;
  7.     else
  8.         return f(x-2)+f(x-1);
  9. }
  10. int main()
  11. {
  12.     int x;
  13.     cout<<"要推算到第幾項次? ";
  14.     cin>>x;
  15.     for(int i=0; i<=x; i++)
  16.         cout<<"第"<<i<<"項次為:"<<f(i)<<endl;
  17.     cout<<endl;
  18.     system("pause");
  19.     return 0;
  20. }
複製代碼

TOP

返回列表