主题:[活动]QB解算术
神鬼天王
[专家分:30] 发布于 2009-09-13 10:25:00
快
回复列表 (共1个回复)
沙发
phile [专家分:2310] 发布于 2009-09-13 10:28:00
CLS
INPUT A$
L = LEN(A$)
DIM A$(L), B(L)
PRINT A$; "=";
DO
Q = INSTR(A$, ")")
IF Q <> 0 THEN
K = 0
DO
K = INSTR(K + 1, A$, "(")
IF K < Q AND K <> 0 THEN P = K
LOOP UNTIL K = 0 OR K > Q
AA$ = MID$(A$, 1, P - 1)
AB$ = MID$(A$, P + 1, Q - (P + 1))
AC$ = MID$(A$, Q + 1)
GOSUB 100
AB$ = LTRIM$(STR$(B(1)))
A$ = AA$ + AB$ + AC$
END IF
LOOP UNTIL Q = 0
AB$ = A$
GOSUB 100
PRINT USING"########.#####";B(1)
END
100
T$ = ""
J = 1
LA = LEN(AB$)
FOR I = 1 TO LA
X$ = MID$(AB$, I, 1)
IF X$ = "-" AND MID$(AB$ , I + 1,1)>="0" AND MID$(AB$ ,I + 1, 1)<="9" THEN
T$=T$+X$
ELSEIF X$ = "+" OR X$ = "-" OR X$ = "*" OR X$ = "/" OR X$ = "\" X$ = "^" OR X$="M" THEN
IF X$ = "M" THEN
X$=X$+MID$(AB$ ,I + 1,2)
I=I+2
END IF
A$(J) = X$
B(J) = VAL(T$)
T$ = ""
J = J + 1
ELSE
T$ = T$ + X$
END IF
NEXT I
B(J) = VAL(T$)
FOR T = 1 TO J
IF A$(T) = "^" THEN B(T) = B(T) ^ B(T + 1): GOSUB 200
NEXT T
FOR T = 1 TO J
IF A$(T) = "*" THEN B(T) = B(T) * B(T + 1): GOSUB 200
IF A$(T) = "/" THEN B(T) = B(T) / B(T + 1): GOSUB 200
NEXT T
FOR T = 1 TO J
IF A$(T) ="\" TTHEN B(T) = B(T) \ B(T + 1): GOSUB 200
NEXT T
FOR T=1 TO J
IF A$(T) = "MOD" THEN B(T) = B(T) MOD B(T + 1):GOSUB 200
FOR T = 1 TO J
IF A$(T) = "+" THEN B(T) = B(T) + B(T + 1): GOSUB 200
IF A$(T) = "-" THEN B(T) = B(T) - B(T + 1): GOSUB 200
NEXT T
RETURN
200
FOR P = T TO LA - 2
A$(P) = A$(P + 1)
B(P + 1) = B(P + 2)
NEXT P
J = J - 1
T = T - 1
RETURN
我来回复