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
Comment on c++ standard exceptions?
Describe about storage allocation and scope of global, extern, static, local and register variables?
Write a Program to find the largest of 4 no using macros.
which operator is used for performing an exponential operation a) > b) ^ c) none
Explain bubble sorting.
Why are pointers not used in c++?
How can virtual functions in c++ be implemented?
why is c++ called oops? Explain
What is the difference between while and do while loop? Explain with examples.
Can we specify variable field width in a scanf() format string? If possible how?
What are the advantages of using pointers in a program?
What are the advantages of pointers?
What is the basic difference between C and C++?
Can a program run without main function?
Explain what are mutator methods in c++?