Given a stream of numbers, your task is to calculate the sum up until the first nonnegative number. All the numbers after the first nonnegative one should be ignored.
The program should print the required sum.
Input | Output |
-20
-3
-2
-30
0
-1 | -55 |
Explanation: The first nonnegative number in the list
-20, -3, -2, -30, 0, -1
is 0
. So, we should calculate the sum of numbers before 0
. This results in -20 -3 -2 -30 = -55
.