- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int count(int a,int b)
- {
- int total=b;
- if(a>0)
- {
-
- total=total+a;
- a--;
- return count(a,total);
- }
- else
- {
- return total;
- }
- }
- int count2(int c,int d)
- {
- int total2=d;
- if(c>0)
- {
- total2=total2+c;
- c--;
- return count2(c,total2);
- }
- else
- {
- return total2;
- }
- }
- int main()
- {
- int a=1;
- int b=10;
- cout<<count(10,0)<<endl;
- cout<<count(100,0)<<endl;
- system("pause");
- return 0;
- }
複製代碼 |