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
Explain what is #line used for?
What is character constants?
What is the difference between array and structure in c?
What are the header files used in c language?
What is unary operator?
What is void c?
What does return 1 means in c?
Write the syntax and purpose of a switch statement in C.
What does the file stdio.h contain?
In which layer of the network datastructure format change is done
Can a file other than a .h file be included with #include?
How can I do graphics in c?
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.
Differentiate between declaring a variable and defining a variable?
Are the outer parentheses in return statements really optional?