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


Please Help Members By Posting Answers For Below Questions

Do you know null pointer?

611


What Is The Difference Between Null And Void Pointer?

644


Is it fine to write void main () or main () in c?

547


What is ponter?

772


How can I run c program?

688






Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10

15048


What is the mean of function?

649


pgm to find any error in linklist(in single linklist check whether any node points any of previous nodes instead of next node)

2201


What is an operator?

656


Explain about C function prototype?

611


What is optimization in c?

568


Are pointers really faster than arrays?

562


Why c is a procedural language?

583


What is the basic structure of c?

557


Explain what does the function toupper() do?

634