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 / jagadish
The answer would be
b.
11 Its recursive function.so track for the returns
1st return:fn(v-1)+3;::v=7
2nd return fn(v/2)+2;::v=6
3rd return fn(v-1)+3;::v=3
4th return fn(v/2)+2;::v=2
5th return 1;::v=1
finally its 11=1+2+3+2+3
| Is This Answer Correct ? | 6 Yes | 0 No |
Post New Answer View All Answers
Is there any difference between int [] a and int a [] in c++?
What is scope operator in c++?
Is c# written in c++?
What is c++ manipulator?
Can a built-in function be recursive?
What are the various arithmetic operators in c++?
What is abstraction in c++?
What is switch case in c++ syntax?
What is the difference between function overloading and operator overloading?
What is polymorphism and its type in c++?
write asingle linked list which read from two list & the do the following 1 sort the prime & nonprime num (prime should be less tn nonprime) 2 each node has a prime num followd by nonprime 3 add a new node into its sutable plce 4 erase the most three duplicated non prime num 5 find the least duplicated prime num
Can create new c++ operators?
What is private inheritance?
What is std namespace in c++?
What is buffer and example?