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
Answers were Sorted based on User's Feedback
Answer / babita sharma
The answer would be
b.
11 Its teh recursive function.
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / 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 |
How are virtual functions implemented in c++?
What is late binding c++?
Differentiate between a copy constructor and an overloaded assignment operator.
Explain public, protected, private in c++?
What is the benefit of c++?
What is polymorphism and its type in c++?
Explain the advantages of using friend classes.
Given an array of size N in which every number is between 1 and N, determine if there are any duplicates in it. You are allowed to destroy the array if you like. [ I ended up giving about 4 or 5 different solutions for this, each supposedly better than the others ].
Can union be self referenced?
Mention the ways in which parameterized can be invoked. Give an example of each.
difference between c and c++?
38 Answers Cognizant, IBM, Infosys, Oracle, Sarva Shiksha Abhiyan, Wipro,
When you overload member functions, in what ways must they differ?