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
Write a program in "C" to calculate the root of a quadratic equation ax^2+bx+c=0, where the value of a,b & c are known.
When should we use pointers in a c program?
What are pointers? What are different types of pointers?
What is uint8 in c?
Explain which function in c can be used to append a string to another string?
i want to switch my career from quailty assurance engineering to development kindly guide me from which programming language its better for me to start plz refer some courses or certifications too i have an experience of 1.5 yrs in QA field.Kindly guide me
The performance of an operation in several steps with each step using the output of the preceding step a) recursion b) search c) call by value d) call by reference
What are the different properties of variable number of arguments?
What are reserved words?
How can I read in an object file and jump to locations in it?
Who invented bcpl language?
What is data types?
What are the types of type qualifiers in c?
What is return in c programming?
How does placing some code lines between the comment symbol help in debugging the code?