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 / lakshmi
first it checkes the main function i.e., fn()
int fn(7)
if(7==1||v==0) : this is false so the complier executes
the next if condition
if(7%2==0) : This is false so it executes the else
instruction
return fn(6)+3; :here we are again calling the fn
function .So the loop executes till the 7 becomes 1
After this the first if condition is true so it rerurns 1
to the function fn(1)+3
so the answer is 1.
| Is This Answer Correct ? | 0 Yes | 7 No |
Post New Answer View All Answers
How can I find the modification date of a file?
Why is python slower than c?
What is #define?
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
Write a program to check palindrome number in c programming?
how we can make 3d venturing graphics on outer interface
What does a function declared as pascal do differently?
What are structural members?
What does %p mean?
What is the size of array float a(10)?
Can we use any name in place of argv and argc as command line arguments?
What is meant by recursion?
Can we use visual studio for c?
How can I delete a file?
What do you understand by normalization of pointers?