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
Does free set pointer to null?
Explain what is a program flowchart and explain how does it help in writing a program?
Are pointers really faster than arrays?
Is this program statement valid? INT = 10.50;
Differentiate between calloc and malloc.
What is meant by realloc()?
What are logical errors and how does it differ from syntax errors?
What is the difference between array and pointer?
How can I find the modification date of a file?
Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?
Wt are the Buses in C Language
Write a program to swap two numbers without using a temporary variable?
What does stand for?
Define macros.
What is the difference between strcpy() and memcpy() function in c programming?