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 are manipulators used for?
Where Malloc(), Calloc(), and realloc() does get memory?
What is c++ try block?
Evaluate as true or false: !(1 &&0 || !1) a) True b) False c) Invalid statement
Can the operator == be overloaded for comparing two arrays consisting of characters by using string comparison?
Is it possible to use a new for the reallocation of pointers ?
Differentiate between a constructor and a destructor in c++.
What is a map in c++?
Difference between pointer to constant and constant pointer to a constant. Give example.
What's the "software peter principleā?
What are the two types of comments, and how do they differ?
Why c++ does not have finally?
How do you establish an is-a relationship?
Is it legal in c++ to overload operator++ so that it decrements a value in your class?
What are the advantages of using const reference arguments in a function?