主题:“高精度四则运算”的程序怎么编?
剑圣风暴
[专家分:450] 发布于 2007-07-22 07:48:00
请教各位高人,“高精度四则运算”的程序怎么编?
回复列表 (共21个回复)
沙发
Matodied [专家分:7560] 发布于 2007-07-22 07:53:00
楼主的用户名好好玩哦!
有关内容请见我同学发的两个帖子:
[url=http://www.programfan.com/club/post-229949.html]来就送分![/url]
[url=http://www.programfan.com/club/post-230326.html]来就送分(2)[/url]
板凳
紫蝶公主 [专家分:30] 发布于 2007-07-23 08:34:00
加法
CLS:INPUT A$,B$:LA=LEN(A$):LB=LEN(B$)
IF LB>LA THEN SWAP A$,B$:SWAP LA,LB
N=LA+1:DIM A(N),B(N)
FOR I=1 TO LA
A(I)=VAL(MID$(A$,LA+1-I,1)
NEXT I
FOR I=1 TO LB
B(I)=VAL(MID$(B$,LB+1-I,1)
NEXT I
FOR I=1 TO LA
X=A(I)+B(I):A(I+1)=A(I+1)+X\10:A(I)=X MOD 10
NEXT I
IF A(N)=0 THEN N=N-1
FOR I=N TO 1 STEP -1:PRINT USING "#";A(I);NEXT I
3 楼
紫蝶公主 [专家分:30] 发布于 2007-07-23 09:08:00
CLS:INPUT A$,B$:LA=LEN(A$):LB=LEN(B$):A1$=A$:B1$=B$
IF LB>LA OR LA=BL AND B$>A$ THEN SWAP A$,B$:SWAP LA,LB:C$="-"
DIM A(LA),B(LA)
FOR I=1 TO LA
A(I)=VAL(MID$(A$,LA+1-I,1)
NEXT I
FOR I=1 TO LB
B(I)=VAL(MID$(B$,LB+1-I,1)
NEXT I
FOR I=1 TO LA
A(I)=A(I)-B(I)
A(I+1)=A(I+1)+(A(I)<0)
A(I)=A(I)-(A(I)<0)*10
NEXT I
PRINT A1$;"-";B1$;"=";
DO WHILE A(N)=0 AND N>1:N=N-1:LOOP
IF C$="-" THEN PRINT "-";
FOR I=N TO 1 STEP -1:PRINT USING"#";A(I);:NEXT I
END
4 楼
紫蝶公主 [专家分:30] 发布于 2007-07-23 09:18:00
怎么不加分???
5 楼
冷石_jasv [专家分:1570] 发布于 2007-07-23 12:47:00
moz以前写过这方面的贴.你可以自己去论坛里找找.
原理就是....我们用脑袋怎么算加减乘除...你就怎么写..进位运算.小学的内容了
6 楼
剑圣风暴 [专家分:450] 发布于 2007-07-23 17:48:00
晕!!!!!!!!!!
7 楼
V2战警2 [专家分:390] 发布于 2007-07-24 16:40:00
加法:
INPUT A$,B$
8 楼
V2战警2 [专家分:390] 发布于 2007-07-24 17:14:00
[fly]加法[/fly]
INPUT A$,B$
LA=LEN (A$):LB=LEN(B$)
IF LB>LA THEN SWAP A$,B$:SWAP LA,LB
N=LA+1:DIM A(N),B(N)
FOR I=1TO N:A(I)=0;B(I)=0:NEXT I
FOR I=1TO LA:A(I)=VAL(MID$(A$,N-I,1)):NEXT I
FOR I=1TO LB:B(I)=VAL(MID$(B$,LB+1-I,1):NEXT I
FOR I=1TO LA:X=A(I)+B(I):A(I+1)=A(I+1)+X\10:A(I)=X MOD 10:NEXT I
?A$;"+";B$;"=";
IF A(N)=0 THEN N=N-1
FRO I=N T0 1 STEP-1:PRINT USING"#";A(I):NEXT I
END
[fly]减法[/fly]
INPUT A$,B$
LA=LEN(A$):LB=LEN(B$)
A1$=A$:B1$=B$
IF LA<LB THEN SWAP LA,LB:SWAP A$,B$:C$="-"
N=LA:DIM A(N),B(N)
FOR I=1TO LA:A(I)=VAL(MID$(A$,N-I,1)):NEXT I
FOR I=1TO LB:B(I0=VAL(MID$(B$,LB-I,1)):NEXT I
FOR I=1TO N
A(I)=A(I)-B(I)
A(I+1)=A(I+1)+(A(I)<0)
A(I)=A(I)-(A(I)<0)*10
NEXT I
PRINT A1$;"-";B1$;"=";
DO WHILE A(N)=0AND N>1:N=N-1:NEXT I
IF C$="-" THEN PRINT"-";
FOR I=N TO 1 STEP-1:?USING"#";A(I);:NEXT I
[fly]乘法[/fly]
INOUT A4,B$
LA=LEN(A$):L=LEN(B$):LC=LA+LB
DIM A(LA),B(LB),C(LC)
FOR I=1TO LA:A(I)=VAL(MID$(A$,LA-I,1)):NEXT I
FOR I=1TO LB:B(I)=VAL(MID$(B$,LB-I,1)):NEXT I
FOR I=1 TO LA:FOR J=1TO LB
X=A(I)*B(I):C(W)=C(W)+X MOD 10
C(W+1)=C(W+1)+C(W)\10+X\10
C(W)=C(W) MOD 10
NEXT J,I
PRINT A$;"*";B$;"=";
WHILE C(LC)=0:LC=LC-1:WEND
FOR I=LC TO 1 STEP -1:PRINT USING"#";C(I):NEXT I
(除法太烦了,略~)
当心看的哦
[em15][em19][em23][em7][em15][em19][em18]
9 楼
V2战警2 [专家分:390] 发布于 2007-07-24 17:16:00
加法
INPUT A$,B$
LA=LEN (A$):LB=LEN(B$)
IF LB>LA THEN SWAP A$,B$:SWAP LA,LB
N=LA+1:DIM A(N),B(N)
FOR I=1TO N:A(I)=0;B(I)=0:NEXT I
FOR I=1TO LA:A(I)=VAL(MID$(A$,N-I,1)):NEXT I
FOR I=1TO LB:B(I)=VAL(MID$(B$,LB+1-I,1):NEXT I
FOR I=1TO LA:X=A(I)+B(I):A(I+1)=A(I+1)+X\10:A(I)=X MOD 10:NEXT I
?A$;"+";B$;"=";
IF A(N)=0 THEN N=N-1
FRO I=N T0 1 STEP-1:PRINT USING"#";A(I):NEXT I
END
减法
INPUT A$,B$
LA=LEN(A$):LB=LEN(B$)
A1$=A$:B1$=B$
IF LA<LB THEN SWAP LA,LB:SWAP A$,B$:C$="-"
N=LA:DIM A(N),B(N)
FOR I=1TO LA:A(I)=VAL(MID$(A$,N-I,1)):NEXT I
FOR I=1TO LB:B(I0=VAL(MID$(B$,LB-I,1)):NEXT I
FOR I=1TO N
A(I)=A(I)-B(I)
A(I+1)=A(I+1)+(A(I)<0)
A(I)=A(I)-(A(I)<0)*10
NEXT I
PRINT A1$;"-";B1$;"=";
DO WHILE A(N)=0AND N>1:N=N-1:NEXT I
IF C$="-" THEN PRINT"-";
FOR I=N TO 1 STEP-1:?USING"#";A(I);:NEXT I
乘法
INOUT A4,B$
LA=LEN(A$):L=LEN(B$):LC=LA+LB
DIM A(LA),B(LB),C(LC)
FOR I=1TO LA:A(I)=VAL(MID$(A$,LA-I,1)):NEXT I
FOR I=1TO LB:B(I)=VAL(MID$(B$,LB-I,1)):NEXT I
FOR I=1 TO LA:FOR J=1TO LB
X=A(I)*B(I):C(W)=C(W)+X MOD 10
C(W+1)=C(W+1)+C(W)\10+X\10
C(W)=C(W) MOD 10
NEXT J,I
PRINT A$;"*";B$;"=";
WHILE C(LC)=0:LC=LC-1:WEND
FOR I=LC TO 1 STEP -1:PRINT USING"#";C(I):NEXT I
(除法太烦了,略~)
当心看的哦
[em15][em19][em23][em7][em15][em19][em18][/quote]
10 楼
wzc1996 [专家分:1680] 发布于 2007-07-24 19:24:00
乘法!
CLS
INPUT a$, b$
la = LEN(a$): lb = LEN(b$)
DIM a(la), b(lb), d(la, lb), k(la + lb)
FOR i = 1 TO la: a(i) = VAL(MID$(a$, i, 1)): NEXT
FOR i = 1 TO lb: b(i) = VAL(MID$(b$, i, 1)): NEXT
FOR i = 1 TO la
FOR j = 1 TO lb
d(i, j) = a(i) * a(j)
NEXT: NEXT
FOR i = 1 TO la
FOR j = 1 TO lb
k(i + j) = k(i + j) + d(i, j): NEXT: NEXT
FOR i = la + lb TO 2 STEP -1
IF k(i) >= 10 THEN k(i - 1) = k(i - 1) + k(i) \ 10: k(i) = k(i) MOD 10:
NEXT
PRINT a$; "*"; b$; "="; :
FOR i = 1 TO la + lb: IF k(1) = 0 THEN 10: PRINT k(i);
NEXT:
10 FOR i = 2 TO la + lb: PRINT k(i);
NEXT
我来回复