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
How do you override a defined macro?
Explain what are bus errors, memory faults, and core dumps?
Why c language?
In a switch statement, explain what will happen if a break statement is omitted?
What is wild pointer in c with example?
a parameter passed between a calling program and a called program a) variable b) constant c) argument d) all of the above
What are the modifiers available in c programming language?
What does stand for?
Here is a good puzzle: how do you write a program which produces its own source code as output?
What is a method in c?
How can I remove the trailing spaces from a string?
What is the meaning of 2d in c?
What is register variable in c language?
Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result
What is use of #include in c?