CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

What is the value printed by the following C program?
#include <stido.h>
int f (int *a, int n)
{
if (n <= 0) return 0;
else if (*a % 2 == 0)
return *a + f(a + 1, n - 1);
else return *a -f(a + 1, n - 1);
}
int main ( )
{
int a [ ] = {12, 7, 13, 4, 11, 6};
printf("%d", f(a,6));
return 0;
}

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

The correct option is A 15
So f(a, 6) first this call
Thus is the number stored in the array and we can access these by using
*a - f(a, 6)

So 12 +f(a + 1, n - 1) {even}

7- f(a + 1, n - 1) {odd}

13 - f(a + 1, n - 1) {odd}

4 + f(a + 1, n - 1) {even}

11 - f(a +1, n - 1) {odd}

6 + f(a + 1, 0) {even}

0
= 12 + [7 - [13 - [4+ [11- (6 +0)]]]]
= 12 + [7 - [13- [4 + [11 - 6]]]
= 12 + [7 - [13 - [4 + 5]]] = 12 + (7 - (13 - 9))
= 12 + ( 7 -4) = 12 + 3 = 15

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Heat Capacity
CHEMISTRY
Watch in App
Join BYJU'S Learning Program
CrossIcon