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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started