问题描述
每当我运行程序时,输入 2 for x
2 for y
它会产生 4,这很好,但是每当我输入 2 的 3 次方时,它输出 9
它应该输出 8,当我做 3 的 2 次方时它输出 8,它应该给出 9。它适用于 2^2、2^4 但不适用于 2^3。同样 8^8 给出 256
。程序写错了吗?
/ Start of the main program
Input / Enter the exponent Store y
Subt One
Store Count
Input / Enter the Base
Store x
Store y
Jns Exp
/ Ending the main program
Load Ans
Output
End,Halt
Exp,Hex 0
Loop2,Load Count
Skipcond 800
JumpI Exp
JnS Multiplier
Load Ans
Store x
Load Count
Subt One
Store Count
Jump Loop2
/ Start of the subroutine Multiplier
Multiplier,Hex 0
Load Zero
Store Ans
Loop,Load x
Skipcond 800
JumpI Multiplier
Load Ans
Add y
Store Ans
Load x
Subt One
Store x
Jump Loop
/ Declaration
x,Dec 2
y,Dec 3
Zero,Dec 0
One,Dec 1
Ans,Dec 0
Count,Dec 0
解决方法
你的论点倒过来了。您对 2**3
和 3**2
的结果只是倒退。 2**2
和 2**4
不受参数顺序的影响。
用 16 位数字表示 8**8
是不可能的,因为那是 0x1000000
,所以你总是会得到错误的结果。
您的代码首先取指数,然后取基数。
我使用 **
约定表示指数而不是 ^
,因为后者在大多数编程语言中用于表示异或。