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

Comment on c++ standard exceptions?

841


Describe about storage allocation and scope of global, extern, static, local and register variables?

992


Write a Program to find the largest of 4 no using macros.

796


which operator is used for performing an exponential operation a) > b) ^ c) none

785


Explain bubble sorting.

802


Why are pointers not used in c++?

804


How can virtual functions in c++ be implemented?

810


why is c++ called oops? Explain

781


What is the difference between while and do while loop? Explain with examples.

821


Can we specify variable field width in a scanf() format string? If possible how?

878


What are the advantages of using pointers in a program?

868


What are the advantages of pointers?

793


What is the basic difference between C and C++?

812


Can a program run without main function?

860


Explain what are mutator methods in c++?

750