Evaluate:
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);
a) 10
b) 11
c) 1
Answer Posted / jagadish
The answer would be
b.
11 Its recursive function.so track for the returns
1st return:fn(v-1)+3;::v=7
2nd return fn(v/2)+2;::v=6
3rd return fn(v-1)+3;::v=3
4th return fn(v/2)+2;::v=2
5th return 1;::v=1
finally its 11=1+2+3+2+3
Is This Answer Correct ? | 6 Yes | 0 No |
Post New Answer View All Answers
What are the differences between malloc() and calloc()?
What is the basic difference between C and C++?
What is prototype in c++ with example?
explain the reference variable in c++?
Which operator cannot overload?
Evaluate !(1&&1||1&&0) a) Error b) False c) True
What do you mean by translation unit in c++?
What is atoi in c++?
What is an inclusion guard?
What is the two main roles of operating system?
What does the following code do: int c=0; cout< a) Undefined *Updated* b) 01 c) 00
What is conditions when using boolean operators?
How do you compile the source code with your compiler?
Write a single instruction that will store an EVEN random integer between 54 and 212 inclusive in the variable myran. (NOTE only generate EVEN random numbers)
What is function prototyping?