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
Answers were Sorted based on User's Feedback
Answer / babita sharma
The answer would be
b.
11 Its teh recursive function.
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / jagdish patel
you have wrong option
correct answer is 9
solution:-
v=7;
so v is not =1,0 and also v%2 is not 0;
so (v-1)+3;
(7-1) + 3
6 + 3
= 9
| Is This Answer Correct ? | 3 Yes | 8 No |
What is the function of the keyword ‘volatile’ in C++?
Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?
Write a corrected statement in c++ so that the statement will work properly. if (x > 5); y = 2*x; else y += 3+x;
When the design recommends static functions?
What is the C-style character string?
Can member data be public?
Ask to write virtual base class code?
Describe functional overloading?
What is the size of pointer ? Also size of pointer in 64 bit pointer
how to create window program in c++.please explain.
What are the methods of exporting a function from a dll?
What is encapsulation in c++ with example?