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 to capitalise first letter of each word in a given string?

1867


Difference between constant pointer and pointer to a constant.

1064


What is a pointer on a pointer in c programming language?

1091


What is the difference between test design and test case design?

2028


Should a function contain a return statement if it does not return a value?

1012


What is huge pointer in c?

1022


Explain about the constants which help in debugging?

1307


any function have arguments one or more OR not . it is compulsary a) any function compulsary have one or more arguments b) any function did not have arguments. It is not compulsary c) it is optional it is not compulsary d) none of the above

1056


Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.

3635


How is a pointer variable declared?

1022


What do you mean by keywords in c?

1080


Write a c program to build a heap method using Pointer to function and pointer to structure ?

4621


What is calloc() function?

1047


What is s in c?

994


Where are local variables stored in c?

981