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
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
How do you determine a file’s attributes?
What are the types of pointers in c?
What's the right way to use errno?
#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); }
When should you not use a type cast?
What is the purpose of scanf() and printf() functions?
What is the g value paradox?
Explain how do you override a defined macro?
What is chain pointer in c?
#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); }
hi any body pls give me company name interview conduct "c" language only
Is c object oriented?
What is difference between stdio h and conio h?
What are loops c?