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 does struct node * mean?
Which one would you prefer - a macro or a function?
What is string concatenation in c?
What is the use of ?
Why main function is special give two reasons?
Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)
How do I use strcmp?
Describe explain how arrays can be passed to a user defined function
The statement, int(*x[]) () what does in indicate?
What is %s and %d in c?
Is c object oriented?
Explain how can I pad a string to a known length?
provide an example of the Group by clause, when would you use this clause
What is difference between structure and union with example?
Why pointers are used?