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
declare an array of structure where the members of the structure are integer variable float variable integer array char variable access all elements of the structure using dot operator and this pointer operator
Can we overload operator in c++?
How a new operator differs from the operator new?
How many types of comments are there in c++?
How do you write a function that can reverse a linked-list?
What is the full name of logo?
What will strcmp("Astring", "Astring"); return a) A positive value b) A negative value c) Zero
Explain overriding.
What is #include iostream h in c++?
Why ctype h is used in c++?
How can you quickly find the number of elements stored in a static array?
Can you please explain the difference between overloading and overriding?
What is pointer with example?
What do you mean by vtable and vptr in c++?
What is public, protected, private in c++?