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
How can you return multiple values from a function?
Can one function call another?
how can I convert a string to a number?
using only #include
what will be the output for the following main() { printf("hi" "hello"); }
Explain can you assign a different address to an array tag?
Tell us bitwise shift operators?
what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)
Explain how do you generate random numbers in c?
What are the modifiers available in c programming language?
What is #include conio h?
What is a pointer variable in c language?
Explain what is the use of a semicolon (;) at the end of every program statement?
void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }
What is pointers in c with example?