Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions

Question

If ( A^2 - A + I = 0 ), then inverse of matrix ( A ) is?

Answered: 1 week ago

Question

What is computer neworking ?

Answered: 1 week ago

Question

Has the team been empowered to prioritize the issues?

Answered: 1 week ago

Question

b. Does senior management trust the team?

Answered: 1 week ago

Question

c. How is trust demonstrated?

Answered: 1 week ago