wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Consider the following C function:
int f (int n)
{ static int r = 0;
if (n< 0) return 1;
if (n > 3)
{
r = n;
return f(n - 2) +2
}
return f(n-1) +r;
}
What is the value of f(5)?

A
18
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
B
5
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
7
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
9
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is A 18
To compute f(5), initially r=5.
f(3)+2=18[(n>3):f(n2)+2]f(2)+5=16[f(n2)+r]f(1)+5=11[f(n2)+4]f(0)+5=6[f(n2)+4]1[n0]

flag
Suggest Corrections
thumbs-up
1
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Theorems on Integration
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon