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 / chandrakala
this program returns the result as
1.
because,
7 is not equal to 1 or 0 and it is not mod by 2. so it will
go to else condition .in that 7-1 is performed and it mod
by 2 so 6/2=3 it once again go to else 3-1=2 is enter in to
function 2%2\=0 so 2/2 is performed.now v is 1 so it
returns 1 as answer.
| Is This Answer Correct ? | 5 Yes | 8 No |
Post New Answer View All Answers
What is a global variable in c?
State the difference between x3 and x[3].
What does c mean in standard form?
Explain what are bus errors, memory faults, and core dumps?
I need testPalindrome and removeSpace
#include
How to implement a packet in C
What is new line escape sequence?
What is output redirection?
List some of the static data structures in C?
How many levels of pointers can you have?
By using C language input a date into it and if it is right?
What is %g in c?
write a program to create a sparse matrix using dynamic memory allocation.
Is main is user defined function?
How can I remove the leading spaces from a string?