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 / abdur rab

The answer is 11

( 7 - 1 ) + 3 -> 11 = (8 +3)

( 6 / 2 ) + 2 --> 8 = (6 +2)

( 3 - 1 ) + 3 ---> 6 = (3 +3)

( 2 / 2 ) + 2 ----> 3 = (1 +2)

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you override a defined macro?

704


Explain what are bus errors, memory faults, and core dumps?

794


Why c language?

652


In a switch statement, explain what will happen if a break statement is omitted?

641


What is wild pointer in c with example?

581






a parameter passed between a calling program and a called program a) variable b) constant c) argument d) all of the above

659


What are the modifiers available in c programming language?

743


What does stand for?

601


Here is a good puzzle: how do you write a program which produces its own source code as output?

602


What is a method in c?

630


How can I remove the trailing spaces from a string?

618


What is the meaning of 2d in c?

617


What is register variable in c language?

609


Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result

1472


What is use of #include in c?

603