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

Which field is used in c++?

723


Are there interfaces in c++?

661


What is a class definition?

704


What is a c++ object?

717


What is a loop? What are different types of loops in c++?

692






What is c++ iterator?

739


what are the iterator and generic algorithms.

1571


What is scope resolution operator in c++ with example?

639


How do we balance an AVL Tree in C++?

733


What is expression parser in c++

2007


What is different in C++, compare with unix?

700


What is a sequence in c++?

662


What is fflush c++?

661


Describe the process of creation and destruction of a derived class object?

740


What is doubly linked list in c++?

734