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 / chandrakala

this program returns the result as

1.


because,
7 is not equal to 1 or 0 and it is not mod by 2. so it will
go to else condition .in that 7-1 is performed and it mod
by 2 so 6/2=3 it once again go to else 3-1=2 is enter in to
function 2%2\=0 so 2/2 is performed.now v is 1 so it
returns 1 as answer.

Is This Answer Correct ?    5 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what is #line used for?

597


What is character constants?

704


What is the difference between array and structure in c?

561


What are the header files used in c language?

571


What is unary operator?

646






What is void c?

558


What does return 1 means in c?

575


Write the syntax and purpose of a switch statement in C.

608


What does the file stdio.h contain?

595


In which layer of the network datastructure format change is done

1419


Can a file other than a .h file be included with #include?

672


How can I do graphics in c?

584


write a program to reverse a every alternetive words in a string in a place. EX: Input is "this is the line of text" Output should be "shit is eht line fo text" Please any one tell me code for that.

1563


Differentiate between declaring a variable and defining a variable?

596


Are the outer parentheses in return statements really optional?

566