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 / 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 |
Post New Answer View All Answers
What is the difference between structures and unions?
Does c++ have string data type?
Explain terminate() function?
Can create new c++ operators?
total amount of milk produced each morning and then calculates and outputs the number of cartons needed for this milk , the cost of producing the milk and the profit from producing this milk.
Explain the purpose of the keyword volatile.
What is a constant reference?
Which is better c++ or java?
Write about c++ storage classes?
What are the benefits of oop in c++?
What are activex and ole?
What is the difference between the functions rand(), random(), srand() and randomize()?
Are vectors passed by reference c++?
What can c++ be used for?
What is purpose of new operator?