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

TOP

返回列表