Practice
Sum Until Zero
MEDIUMLoops
Read a series of positive integers from the user. Stop when the user enters 0. Output the total of all numbers entered (not counting the 0). If the first number entered is 0, output 0.
Use a WHILE loop.
Input: A sequence of integers ending with 0. Output: The sum of all non-zero entries.
Example:
Input: 5
10
3
0
Output: 18
Premium is coming soon. All grading features are currently unlocked.
Sample Test Cases
Test 1: Basic sum
Inputs: 5, 10, 3, 0
Expected: 18
Test 2: Immediate zero
Inputs: 0
Expected: 0
Test 3: Single number
Inputs: 7, 0
Expected: 7
Ctrl+Enter
Press Ctrl+Enter to run your code
or Ctrl+Shift+Enter to grade