Pseudo-code · Question 27 · Hard
What will be the output of the following pseudocode? (Note: array indices start at 0 and for-loop bounds are inclusive.)
Integer arr[5] = {2, 4, 6, 8, 10}
Integer i
for (i = 0 to 3)
arr[i + 1] = arr[i + 1] + arr[i]
end for
Print arr[4] - arr[2]
- 16
- 20
- 18
- 4
Answer and explanation
Answer: C. 18
Explanation: Each element adds the already-updated previous one, giving running totals [2, 6, 12, 20, 30]. So arr[4] - arr[2] = 30 - 12 = 18.
Previous: What will be the output of the following pseudocode? · Next: What will be the output of the following pseudocode?
Practise pseudo-code
Try a fresh set of pseudo-code questions with an explanation after every answer, free and without signing up: Pseudo-code practice. Or sit a full placement mock test.
More pseudo-code questions
- What will be the output of the following pseudocode?
- What will be the output of the following pseudocode? (Note: &, ^ and >> are…
- What will be the output of the following pseudocode?
- What will be the output of the following pseudocode?
- What will be the output of the following pseudocode? (Note: for-loop bounds…
- What will be the output of the following pseudocode? (Note: for-loop bounds…
More technical & programming practice
C Programming · Java · Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge