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
Write a code to achieve inter processor communication (mutual exclusion implementation pseudo code)?
What is scanf () in c?
What is the purpose of void pointer?
Why is it important to memset a variable, immediately after allocating memory to it ?
What is the value of h?
What is the use of linkage in c language?
Multiply an Integer Number by 2 Without Using Multiplication Operator
What is break in c?
What are derived data types in c?
Is sizeof a keyword in c?
Calculate 1*2*3*____*n using recursive function??
In a switch statement, explain what will happen if a break statement is omitted?
Explain a pre-processor and its advantages.
What is malloc calloc and realloc in c?
C language questions for civil engineering