【问题标题】:Having trouble in writing basic pseudocode在编写基本伪代码时遇到问题
【发布时间】:2021-09-04 12:51:47
【问题描述】:

编写一个伪代码来计算和打印N 整数的乘积。

提示N 是循环的极限。例如,

while y <= N: product = product * y

我不明白这个问题,所以我什么都想不出来,我是新手。

【问题讨论】:

  • 这里的问题是措辞不当的问题陈述;制定这项任务的人做得不好。
  • 欢迎来到 Stackoverflow!,不幸的是,这个问题有点太模糊了,它非常笼统地询问构成教程的内容,而不是询问具体问题。因此它不适合 stackoverflow,因为 Stackoverflow 不是教程提供者或免费的代码编写服务,我建议新用户查看 stackoverflow 的 How to ask 部分,以获取有关提出非常适合该站点并最好启用的问题的提示社区提供有用的反馈。祝你好运:)

标签: pseudocode


【解决方案1】:
PRINT("N = __")    // Asks the user to input what "n" is
n <-- INT(USERINPUT) // The answer must be an integer (non-decimal). It saves this to the variable "n".

y <-- [] // Makes a blank array called "y"

FOR n: // Allows the below code to run as a maximum, "n" times. It's a loop, so repeats.
    PRINT("Add the number: ") // Asks the user to input an integer
    input <-- (USERINPUT)     // For the first iteration (loop), it saves the answer to "y", but for the other loops, it replaces the previous value
    IF input == "break" THEN: // If the user answered "break" - it is case-sensitive.
 ​       print (y) // Prints our array with our integers
        break // Ends the code
    ELSE: // If the user did not answer "break".
        y.append(input) // Appends (adds) our answer to the array "y"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-26
    相关资源
    最近更新 更多