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
How can a program be made to print the line number where an error occurs?
Explain how can I remove the trailing spaces from a string?
Describe the order of precedence with regards to operators in C.
How many types of errors are there in c language? Explain
What is substring in c?
provide an example of the Group by clause, when would you use this clause
what is the significance of static storage class specifier?
HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????
What is the difference between single charater constant and string constant?
What is file in c preprocessor?
What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
Write a C program to accept a matrix of any size. Find the frequency count of each element in the matrix and positions in which they appear in the matrix
What is main () in c?
Explain About fork()?
What is the difference between far and near ?