Indexing starts at 0. What does the code print?
A = [3, 7, 2, 9, 5, 6]
s = 0
for i = 0; i < 6; i = i + 2:
s = s + A[i]
print s- (A)
10
- (B)
22
- (C)
12
- (D)
15
Answer and solution
Answer: (A)
The loop goes through i = 0, 2 and 4.
Those elements are A[0] = 3, A[2] = 2 and A[4] = 5.
Their sum is 3 + 2 + 5 = 10.
The program prints 10.