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


Please Help Members By Posting Answers For Below Questions

What is a function simple definition?

602


What is the stack in c?

709


What are the advantages of using macro in c language?

581


Tell me when would you use a pointer to a function?

594


What is wrong with this initialization?

575






Can a pointer be volatile in c?

524


Explain the advantages of using macro in c language?

566


What is the difference between fread and fwrite function?

629


What is the use of header?

610


What are the primitive data types in c?

561


What are the different types of objects used in c?

560


What is string function in c?

529


What is the difference between struct and union in C?

554


Who developed c language?

630


What is the ANSI C Standard?

768