Question: Dry run the following code and draw the tree to show how recursion is solved. On writing only output you will get zero number. a)

Dry run the following code and draw the tree to show how recursion is solved. On writing only output you will get zero number.

a) fun1(5)

void fun1(int n)

{

int i = 0;

if (n > 1)

fun1(n - 1);

for (i = 0; i < n; i++)

cout << " * ";

}

b) int fun(int a, int b)

{

if (b == 0)

return 0;

if (b % 2 == 0)

return fun(a + a, b/2);

return fun(a + a, b/2) + a;

}

int main()

{

cout << fun(4, 3) ;

return 0;

}

c)

int fun(int n, int* fp)

{

int t, f;

if (n <= 2) {

*fp = 1;

return 1;

}

t = fun(n - 1, fp);

f = t + *fp;

*fp = t;

return f;

}

int main()

{

int x = 15;

cout << fun(5, &x) << endl;

return 0;

}

Dry run these codes on a page (compulsory) and also its output

Send both methods and output

I will thumb up for u

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!