0

编写算法的伪代码,读取不同于零的数字序列,计算偶数和奇数之和。(我们不知道我们必须阅读多少个数字) <-这部分对我来说是有问题的。我假设 A 是数组。

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)

谁能帮我?

4

1 回答 1

2

use a while construct to collect your input - not a for. Break the loop when you get something that isn't a number.

于 2012-10-25T16:47:08.017 回答