返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int wave(int root,int result)
  5. {
  6.     int total=result;
  7.     if(root>0)
  8.     {
  9.         total+=root;
  10.         root--;
  11.         return wave(root,total);
  12.     }
  13.     else
  14.     {
  15.         return total;
  16.     }
  17. }
  18. int wave2(int root,int result)
  19. {
  20.     int total=result;
  21.     if(root>0)
  22.     {
  23.         total+=root;
  24.         root--;
  25.         return wave(root,total);
  26.     }
  27.     else
  28.     {
  29.         return total;
  30.     }
  31. }
  32. int main()
  33. {
  34.     int root=1;
  35.     int result=10;
  36.     cout<<wave(10,0)<<endl;
  37.     cout<<wave2(100,0)<<endl;
  38.     system("pause");
  39.     return 0;
  40. }
複製代碼

TOP

返回列表