Write Chapter 17 5

Write Chapter 17 5
If you want to Find 5th Question of chapter 17

Search this Book

Friday 8 February 2013

Recursion: Chapter 17 > Q.10


Q.10:
#include <iostream>
using namespace std;

int test(int x, int y);

int main()
{
cout << test (5,10) << endl;
cout << test (3,9)  << endl;
}

int test(int x, int y)
{
if (x==y)
return x;
else if (x>y)
return (x+y);
else
return test(x+1,y-1);
}


Output:


a. 15
b. 6

No comments:

Post a Comment