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.11

Q.11

#include <iostream>
using namespace std;

int func(int x);

void main()
{
cout << func(0) << endl;
cout << func(1) << endl;
cout << func(2) << endl;
cout << func(5) << endl;
}

int func(int x)
{
if (x==0)
return 2;
else if (x==1)
return 3;
else
return (func(x-1) + func(x-2));
}


Output:



No comments:

Post a Comment