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


Please Help Members By Posting Answers For Below Questions

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

1739


Can we overload operator in c++?

544


How a new operator differs from the operator new?

620


How many types of comments are there in c++?

572


How do you write a function that can reverse a linked-list?

568






What is the full name of logo?

582


What will strcmp("Astring", "Astring"); return a) A positive value b) A negative value c) Zero

637


Explain overriding.

602


What is #include iostream h in c++?

607


Why ctype h is used in c++?

520


How can you quickly find the number of elements stored in a static array?

632


Can you please explain the difference between overloading and overriding?

588


What is pointer with example?

558


What do you mean by vtable and vptr in c++?

619


What is public, protected, private in c++?

646