返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int calcu(int);
  5. int total(int);
  6. int main()
  7. {
  8.     int x;
  9.     cout<<"輸入欲計算總和到費式數列的第幾項次: ";
  10.     cin>>x;
  11.     cout<<"費式數列前"<<x<<"個項次的總合為"<<total(x)<<endl;
  12.     system("pause");
  13.     return 0;   
  14. }

  15. int total(int x)
  16. {
  17.     int t=0;
  18.     for(int i=1; i<=x; i++)
  19.     t+=calcu(i);
  20.     return t;   
  21. }
  22. int calcu(int x)
  23. {
  24.     if(x<=1)   
  25.        return x;   
  26.     else
  27.        return calcu(x-1)+calcu(x-2);   
  28.    
  29. }
複製代碼

TOP

返回列表