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


Please Help Members By Posting Answers For Below Questions

the statement while(i) puts the entire logic in loop. this loop is called a) indefinite loop b) definite loop c) loop syntax wrong d) none of the above

609


How do you determine a file’s attributes?

605


What are the types of pointers in c?

533


What's the right way to use errno?

628


#include main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf(" %d",*p); *p = 10; printf(" %d %d",i,*p); c = (int*) calloc(2); printf(" %d ",*c); }

633






When should you not use a type cast?

661


What is the purpose of scanf() and printf() functions?

725


What is the g value paradox?

647


Explain how do you override a defined macro?

590


What is chain pointer in c?

605


#define PRINT(int) printf("int = %d ",int) main() {< BR> intx,y,z; x=03;y=02;z=01; PRINT(x^x); z<<=3;PRINT(x); y>>=3;PRINT(y); }

723


hi any body pls give me company name interview conduct "c" language only

1671


Is c object oriented?

544


What is difference between stdio h and conio h?

890


What are loops c?

617