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 the following:
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);




1) 10


2) 11


3) 1

Answer Posted / lakshmi

first it checkes the main function i.e., fn()
int fn(7)
if(7==1||v==0) : this is false so the complier executes
the next if condition
if(7%2==0) : This is false so it executes the else
instruction
return fn(6)+3; :here we are again calling the fn
function .So the loop executes till the 7 becomes 1
After this the first if condition is true so it rerurns 1
to the function fn(1)+3

so the answer is 1.

Is This Answer Correct ?    0 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can I convert a number to a string?

1257


how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?

1981


Differentiate between the = symbol and == symbol?

1369


Which is better between malloc and calloc?

1257


Does sprintf put null character?

1096


Are comments included during the compilation stage and placed in the EXE file as well?

1130


Does c have circular shift operators?

1304


What is scope and lifetime of a variable in c?

1122


plz let me know how to become a telecom protocol tester. thank you.

2243


What is the advantage of c?

1210


Explain the use of keyword 'register' with respect to variables.

1103


How can I copy just a portion of a string?

1370


Why do we use static in c?

1181


I have seen function declarations that look like this

1098


What is a constant?

1113