主题:下面的我计算长整数减法的程序,请看看错在什么地方
DIM x AS STRING, y AS STRING
DIM lenx AS INTEGER, lenY AS INTEGER
DIM result AS STRING
INPUT "x="; x 'x:big
INPUT "y="; y 'y:small
lenx = LEN(x)
lenY = LEN(y)
y = STRING$(lenx - lenY, " ") + y
PRINT " "; x
PRINT "-"; y
PRINT STRING$(lenx + 1, "-")
FOR i = lenx TO 1 STEP -1
IF VAL(MID$(x, i, 1)) >= VAL(MID$(y, i, 1)) THEN
result = RIGHT$(STR$(VAL(MID$(x, i, 1)) - VAL(MID$(y, i, 1))), 1) + result
ELSE
result = RIGHT$(STR$(VAL(MID$(x, i, 1)) + 10 - VAL(MID$(y, i, 1))), 1) + result
[b]x = LEFT$(x, i - 2) + RIGHT$(STR$(VAL(MID$(x, i - 1, 1)) - 1), 1)[/b]
END IF
NEXT
DO
IF LEFT$(result, 1) = "0" THEN
result = RIGHT$(result, LEN(result) - 1)
ELSE
EXIT DO
END IF
LOOP
PRINT STRING$(lenx - LEN(result) + 1, " "); result
要求输入的必须是形如"2354235"这样的数值,没有正负号,也没有小数点并且一定是x>=y(这里没有对x和y的合法性进行验证),估计是加粗那一行,也就是处理进位的部分错了.求改正!(如果有更好的方法,只要是qb实现的)也请发.
DIM lenx AS INTEGER, lenY AS INTEGER
DIM result AS STRING
INPUT "x="; x 'x:big
INPUT "y="; y 'y:small
lenx = LEN(x)
lenY = LEN(y)
y = STRING$(lenx - lenY, " ") + y
PRINT " "; x
PRINT "-"; y
PRINT STRING$(lenx + 1, "-")
FOR i = lenx TO 1 STEP -1
IF VAL(MID$(x, i, 1)) >= VAL(MID$(y, i, 1)) THEN
result = RIGHT$(STR$(VAL(MID$(x, i, 1)) - VAL(MID$(y, i, 1))), 1) + result
ELSE
result = RIGHT$(STR$(VAL(MID$(x, i, 1)) + 10 - VAL(MID$(y, i, 1))), 1) + result
[b]x = LEFT$(x, i - 2) + RIGHT$(STR$(VAL(MID$(x, i - 1, 1)) - 1), 1)[/b]
END IF
NEXT
DO
IF LEFT$(result, 1) = "0" THEN
result = RIGHT$(result, LEN(result) - 1)
ELSE
EXIT DO
END IF
LOOP
PRINT STRING$(lenx - LEN(result) + 1, " "); result
要求输入的必须是形如"2354235"这样的数值,没有正负号,也没有小数点并且一定是x>=y(这里没有对x和y的合法性进行验证),估计是加粗那一行,也就是处理进位的部分错了.求改正!(如果有更好的方法,只要是qb实现的)也请发.