What is printed by int sum = 0; for (int i = 1; i <= 4; i++) sum += i;?
Please select an answer first.
Correct answer: B
The correct answer is 10.
- Trace the program or computing system: Identify the data, variables, objects, control flow, abstraction, network layer, or social impact described in the question.
- Apply the computer science principle: The loop adds 1, 2, 3, and 4, giving 1 + 2 + 3 + 4 = 10.
- Check the result and assumptions: Check types, indexes, order of execution, boundary cases, representation, privacy, reliability, and whether the conclusion follows from the evidence.
The loop adds 1, 2, 3, and 4, giving 1 + 2 + 3 + 4 = 10.
