MARIE,乘以 2 个数字,然后将最终结果除以 2

问题描述 投票:0回答:1
/len = length, hei = height
/get and store input
input
store LEN
input 
store HEI
/start of loop
/load in the value of len
LOOP, load LEN
/add len to num
add NUM
/store the value in num
Store NUM
/load in hei deduct 1 and store back to hei
load HEI
subt ONE
store HEI
/skip jump if the value in the ac is 0 
skipcond 400
jump LOOP
/output
LOOP1, load NUM
subt TWO
store NUM
load NUM
output
skipcond 400
jump LOOP1
load NUM
/end the program
halt

LEN, DEC 0
HEI, DEC 0
ONE, DEC 1
NUM, DEC 0
TWO, DEC 2

我正在尝试编写一个计算三角形面积的程序。我已经设法解决了乘法部分,但是除法部分是我遇到困难的地方。任何帮助将不胜感激。

我尝试进行第二个循环,其中最终乘积会不断地减去 2,但是输出只会多次减去 2 而没有得到正确的答案。例如: `

/len = 3, heigh = 4
/output would be:
/10
/8
/6
/4
/2
/0

就像我之前说的,任何帮助将不胜感激。

multiplication area divide triangle marie
1个回答
0
投票

更改循环以跟踪并返回商

LOOP1, load NUM
subt TWO
store NUM
load QUO     <--
add ONE      <--
store QUO    <--
load NUM
output
skipcond 400
jump LOOP1
load QUO     <--
/end the program
halt

并添加:

QUO, DEC 0
© www.soinside.com 2019 - 2024. All rights reserved.