主题:[活动]高精度除法
神鬼天王
[专家分:30] 发布于 2009-09-13 11:46:00
快急需
回复列表 (共2个回复)
沙发
phile [专家分:2310] 发布于 2009-09-13 11:47:00
CLS
INPUT Q, P
DIM B(100), C(100)
J = 1
P1 = 1
J1 = 0
J2 = 0
B(1) = Q
DO WHILE P1 <> 0 AND Q * 10 <> 0
J1 = J1 + 1
C(J1) = Q * 10 \ P
Q = Q * 10 - C(J1) * P
IF Q = 0 THEN
PRINT "0.";
FOR I = 1 TO J1
PRINT USING "#"; C(I);
NEXT I
END
ELSE
J2 = 0
DO WHILE J2 <= J1 AND B(J2) <> Q
J2 = J2 + 1
LOOP
IF B(J2) = Q THEN
PRINT "0.";
FOR I = 1 TO J2 - 1
PRINT USING "#"; C(I);
NEXT I
PRINT "'";
FOR I = J2 TO J1
PRINT USING "#"; C(I);
NEXT I
PRINT "'"
END
ELSE
J = J + 1
B(J) = Q
END IF
END IF
LOOP
板凳
phile [专家分:2310] 发布于 2009-09-13 11:48:00
CLS
INPUT A$, B$
IF A$ = "0" THEN PRINT A$: END
IF A$ = B$ THEN PRINT "1": END
IF B$ = "1" THEN PRINT A$: END
LA = LEN(A$)
LB = LEN(B$)
IF LA < LB OR LB = LA AND A$ < B$ THEN PRINT "0"; "..."; A$: END
DIM A(LA), B(LA), D(LA)
L = LA
FOR I = 1 TO LA
X$ = MID$(A$, LA + 1 - I, 1)
A(I) = VAL(X$)
NEXT I
FOR I = 1 TO LB
X$ = MID$(B$, LB + 1 - I, 1)
B(I) = VAL(X$)
NEXT I
FOR I = 1 TO LA
D(I) = 0
NEXT I
DO
FOR I = 1 TO LA
A(I) = A(I) - B(I)
IF A(I) < 0 THEN A(I) = A(I) + 10: A(I + 1) = A(I + 1) - 1
NEXT I
K = 1
DO WHILE D(K) = 9
D(K) = 0
K = K + 1
LOOP
D(K) = D(K) + 1
DO WHILE A(LA) = 0 AND LA > 1
LA = LA - 1
LOOP
A$ = ""
FOR I = 1 TO LA
A$ = LTRIM$(STR$(A(I))) + A$
NEXT I
LOOP UNTIL LA < LB OR LA = LB AND A$ < B$
DO WHILE D(L) = 0 AND L > 1
L = L - 1
LOOP
FOR I = L TO 1 STEP -1
PRINT USING "#"; D(I);
NEXT I
IF A$ <> "0" THEN PRINT "..."; A$
我来回复