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 does the following statement mean? int (*a)[4]
What are dynamic type checking?
What are c++ manipulators?
What is the benefit of learning c++?
What function initalizes variables in a class: a) Destructor b) Constitutor c) Constructor
What is microsoft c++ redistributable?
Why cstdlib is used in c++?
What are the advantages of using const reference arguments in a function?
What are the restrictions apply to constructors and destructors?
What is a constructor and how is it called?
What is meant by const_cast?
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.
What are maps in c++?
How would you use the functions randomize() and random()?
Describe the advantage of an external iterator.