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
Do you know null pointer?
What Is The Difference Between Null And Void Pointer?
Is it fine to write void main () or main () in c?
What is ponter?
How can I run c program?
Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10
What is the mean of function?
pgm to find any error in linklist(in single linklist check whether any node points any of previous nodes instead of next node)
What is an operator?
Explain about C function prototype?
What is optimization in c?
Are pointers really faster than arrays?
Why c is a procedural language?
What is the basic structure of c?
Explain what does the function toupper() do?