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
Define VARIABLE?
How can you convert integers to binary or hexadecimal?
What is string function in c?
Explain the use of 'auto' keyword
Define the scope of static variables.
Why do we use pointer to pointer in c?
what is the difference between class and unio?
What are examples of structures?
Where register variables are stored in c?
Write a program with dynamically allocation of variable.
What is the difference between the expression “++a” and “a++”?
How does placing some code lines between the comment symbol help in debugging the code?
Which programming language is best for getting job 2020?
Write a program to print fibonacci series without using recursion?
Can you subtract pointers from each other? Why would you?