0

ユーザーに 2 つの数字を入力するよう求めるプログラムを作成します。次に、プログラムは、2 番目の数値を最初の数値で割った余り (係数) をとった結果を画面 (OUT) に表示します。たとえば、最初に入力した数字が 14 で、2 番目に入力した数字が 5 の場合、プログラムは 4 を表示します。

14 mod 5 = 14 - (2 * 5) = 14 - 10 = 4

14 mod 7 = 14 - (2 * 7) = 14 - 14 = 0

入力された数値は常に正であり、0 より大きいと想定することができます。

こんにちは、これは質問です。この質問を開始する方法がわかりません。

4

4 に答える 4

0

ここでは、減算法を使用してこの除算の問題を解決する必要があります..2つの数値除算の剰余を見つける問題とまったく同じです...

// PRODUCED BY JAMES KHANAL

INP //ask the user
BRZ QUIT // halt the execution if input zero
STA DIVIDEND // store in dividend variable
INP // input dividor
BRZ QUIT // halt the execution if input zero
STA DIVIDOR // store in divider variable
LDA DIVIDEND // load into acc
LOOP STA RESULT // store the temp result
LDA RESULT // load the result
SUB DIVIDOR // subtract the dividor to acc
BRP LOOP //loop if acc is positive or zero 
LDA RESULT // load the result into acc
OUT // display the result
QUIT HLT // halt if brz
HLT // hlt the execution
DIVIDEND DAT //declare variable
DIVISOR DAT //declare variable
于 2014-04-09T00:11:49.657 に答える