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
Can the curly brackets { } be used to enclose a single line of code?
What is the use of extern in c?
What is modeling?
Why c language is called c?
What is #error and use of it?
How can you check to see whether a symbol is defined?
What is extern variable in c with example?
Can you add pointers together? Why would you?
What is memcpy() function?
how should functions be apportioned among source files?
Explain what are binary trees?
What is infinite loop?
What is integer constants?
Explain indirection?
What is meant by type casting?