Reputation: 6540
Write pseudocode of algorithm reading sequence of numbers diffrent than zero which counts sum of even and odd numbers. (we don't know how many numbers we have to read)<-- this part is problematic for me. I assumed A is array.
ALGOR(A)
even <-- 0
odd <--- 0
for i <-- 1 to **???**
n = A[i]
while n > 0
do n <-- n - 2
if n = 0
then even <-- even + n
else
do odd <-- odd + n
write(Odd's sum: ), write(odd), write(\n), write(Even's sum: ), write(even)
Can anyone help me?
Upvotes: 0
Views: 6354
Reputation: 1741
use a while construct to collect your input - not a for. Break the loop when you get something that isn't a number.
Upvotes: 2