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

TOP

返回列表