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

what does the following statement mean? int (*a)[4]

629


What are dynamic type checking?

623


What are c++ manipulators?

616


What is the benefit of learning c++?

562


What function initalizes variables in a class: a) Destructor b) Constitutor c) Constructor

685






What is microsoft c++ redistributable?

626


Why cstdlib is used in c++?

591


What are the advantages of using const reference arguments in a function?

627


What are the restrictions apply to constructors and destructors?

649


What is a constructor and how is it called?

604


What is meant by const_cast?

659


I want to write a C++ language program that: 1. Reads in the size of a square from the screen; 2. Prints a hollow square of that size out of “-“, “|” and blanks on screen; 3. Prints the same hollow square onto a text file. The program should work for squares of all side sizes between 1 and 20.

2304


What are maps in c++?

514


How would you use the functions randomize() and random()?

637


Describe the advantage of an external iterator.

621