Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What is abstract keyword in c++?

1074


What doescout<<(0==0) print out a) 0 b) 1 c) Compiler error: Lvalue required

970


What's the order in which the local objects are destructed?

1268


Can we make any program in c++ without using any header file and what is the shortest program in c++.

1137


Can I learn c++ without c?

1149


Explain storage qualifiers in c++.

1090


Can we define a constructor as virtual in c++?

1132


Is it possible to get the source code back from binary file?

1374


What do you understand by pure virtual function? Write about its use?

1006


Is overriding possible in c++?

1020


Is c++ built on c?

1038


What is c++ similar to?

1188


What is unary operator? List out the different operators involved in the unary operator.

1007


How would you obtain segment and offset addresses from a far address of a memory location?

1088


Can we overload operator in c++?

1044