请帮助我解决这个伪代码算法的错误,并说出我哪里出错了

问题描述 投票:-3回答:1

我需要一些帮助来找到该算法的问题。

该算法应该以10000个数字为输入,计算并输出小于1000的数字。然后计数并输出大于5000的数字。最后输出输入的平均值。如果太乱了,甚至制作一个新的和改进的。

谢谢!

    less=0
     more=0
     total=1
     for x = 0 to 10000
     num= input ("enter a number")
     if num < 1000 then
     less = less + 1
     else
     more = more + 1
     endif
      total = num
      next x
      output ("less: "+ less)
      output("more: "more")
      average = total / 10000
      output ("average: " + average)
algorithm pseudocode
1个回答
-1
投票
  • 缩进和一致的间距使它更易于阅读和理解。

  • 使用0 to 10000表示10001个数字。

  • 您需要total = 0total = total + num(从注释中)以获取正确的总和,并测试大于5000(也从注释中)以获取正确的计数。

  • 一个output语句的引号不正确,并且缺少运算符。


less = 0
more = 0
total = 0
for x = 1 to 10000
    num = input ("enter a number")
    if num < 1000 then
        less = less + 1
    else if num > 5000
            more = more + 1
        endif
    endif
    total = total + num
next x
output ("less: " + less)
output ("more: " + more)
average = total / 10000
output ("average: " + average)
© www.soinside.com 2019 - 2024. All rights reserved.