我正在尝试实现一个循环,该循环接受用户喜欢的任意数量的数字作为输入,然后将其中最大的一个输出为Max = highest number
和N = total number of inputs
当输入为0
时,程序应该停止
这是我到目前为止所做的,但是N和Max没有打印出来?你知道吗
LOOP INP
BRZ F
STA first
BRA LOOP
LOOP INP
BRZ F
STA second
BRA LOOP
SUB second
BRP secondBig
LDA second
OUT
F LDA \n
OTC
LDA N
OTC
LDA =
OTC
secondBig LDA second
LDA \n
OTC
LDA M
OTC
LDA a
OTC
LDA x
OTC
LDA =
OTC
END HLT
N DAT 78
= DAT 61
\n DAT 10
M DAT 77
a DAT 97
x DAT 120
first DAT
second DAT
下面是我在python代码中要做的
number = 0
max = 0
x = int(input(""))
while x != 0:
if x > max:
max = x
number = number + 1
x = int(input(""))
print("n=", number)
if number > 0:
print("max=", max)
我也在努力解决这个问题,但有一些建议:你只需要一个INP。读取输入,启动BRZ循环,并在该循环中调用比较newinp和max的方法(以及对该循环中的输入数进行计数)。你知道吗
至于我的代码,我不能让它打印最大值,只有最后的输入。我试过:(它不是自己的inp,而是从read方法获取inp)
相关问题 更多 >
编程相关推荐