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 do you write a program which produces its own source code as output?
Is c++ based on c?
Explain the difference between #include "..." And #include <...> In c?
what is the different bitween abap and abap-hr?
write a program that reads lines(using getline), converts each line to an integer using atoi, and computes the average of all the numbers read. also compute the standard deviation.
What is a structure and why it is used?
Is exit(status) truly equivalent to returning the same status from main?
What is 1d array in c?
What is selection sort in c?
What is a stream in c programming?
How many levels deep can include files be nested?
What is the argument of a function in c?
why use functions a) writing functions avoids rewriting the same code over and over b) using functions it becomes easier to write programs and keep track of what they are doing c) a & b d) none of the above
What is the maximum no. of arguments that can be given in a command line in C.?
Why main is not a keyword in c?