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
What is the use of lambda in c++?
Why do we need pointers?
What is do..while loops structure?
If you want to share several functions or variables in several files maitaining the consistency how would you share it?
How do you add an element to a set in c++?
What is private public protected in c++?
What is a dynamic binding in c++?
Is c++ the hardest language?
How can you differentiate between inheritance and implementation in c++?
Write a program to find the reverse Fibonacci series starting from N.
Will a recursive function without an end condition every quit, in practice a) Compiler-Specific (Some can convert to an infinite loop) b) No c) Yes
What language is a dll written in?
Explain the use of this pointer?
What are function prototypes?
What is virtual table?