- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int wave(int root,int result)
- {
- int total=result;
- if(root>0)
- {
- total+=root;
- root--;
- return wave(root,total);
- }
- else
- {
- return total;
- }
- }
- int wave2(int root,int result)
- {
- int total=result;
- if(root>0)
- {
- total+=root;
- root--;
- return wave(root,total);
- }
- else
- {
- return total;
- }
- }
- int main()
- {
- int root=1;
- int result=10;
- cout<<wave(10,0)<<endl;
- cout<<wave2(100,0)<<endl;
- system("pause");
- return 0;
- }
複製代碼 |