返回列表 發帖
  1. #include <cstdlib>
  2. #include <iostream>
  3. using namespace std;
  4. int f(int n)
  5. {
  6.      if(n==1)
  7.      {
  8.         return 1;
  9.      }
  10.      else
  11.      {
  12.         return n+f(n-1);   
  13.      }
  14. }
  15. int main()
  16. {
  17.     cout<<"1加到10:"<<f(10)<<endl;   
  18.     cout<<"1加到100:"<<f(100)<<endl;
  19.     cout<<endl;
  20.     system("pause");
  21.     return 0;
  22. }
複製代碼

TOP

返回列表