Evaluate:
int fn(int v)
{
if(v==1 || v==0)
return 1;
if(v%2==0)
return fn(v/2)+2;
else
return fn(v-1)+3;
}
for fn(7);
a) 10
b) 11
c) 1
Answer Posted / jagadish
The answer would be
b.
11 Its recursive function.so track for the returns
1st return:fn(v-1)+3;::v=7
2nd return fn(v/2)+2;::v=6
3rd return fn(v-1)+3;::v=3
4th return fn(v/2)+2;::v=2
5th return 1;::v=1
finally its 11=1+2+3+2+3
| Is This Answer Correct ? | 6 Yes | 0 No |
Post New Answer View All Answers
Which software is best for coding?
Explain stack unwinding.
What are inline functions? What is the syntax for defining an inline function?
Why is c++ so fast?
What is the best book for c++ beginners?
Can you sort a set c++?
what is the difference between linear list linked representaion and linked representation? what is the purpose of representing the linear list in linked represention ? is it not avoiding rules of linear represention?
Is c++ slower than c?
Suppose that data is an array of 1000 integers. Write a single function call that will sort the 100 elements data [222] through data [321].
Write a program that takes a 5 digit number and calculates 2 power that number and prints it.
Can constructor be private in c++?
What is low level language in simple words?
What is the C-style character string?
. If employee B is the boss of A and C is the boss of B and D is the boss of C and E is the boss of D. Then write a program using the Database such that if an employee name is Asked to Display it also display his bosses with his name. For eg. If C is displayed it should also display D and E with C?
What is a set in c++?