Precision Multiplication

See all articles from CATS v3 n2
Author(s): R.A. Schrack
Publication: CATS Newsletter
Pub Details: CATS v3 n2 (Volume 3, Issue 2)
Date: May 1985
Pages: 13
  10 REM
******************************

Precision Multiplication

******************************
20 PRINT "Give number of digits:"
30 INPUT "In first term:";m
40 INPUT "In second term:";n
50 LET k=m+n
52 DIM a(m)
54 DIM b(n)
56 DIM p(k)
58 PRINT
60 PRINT "Give digits of first term"
62 INPUT a$
64 PRINT a$
70 PRINT "Give digits of second term"
72 INPUT b$
74 PRINT b$
76 PRINT
80 FOR i=1 TO m
82 LET a(i)=VAL a$(m-i+1)
84 NEXT i
90 FOR i=1 TO n
92 LET b(i)=VAL b$(n-i+1)
94 NEXT i
100 FOR i=1 TO m
102 LET c=0
104 FOR j=1 TO n
106 LET q=a(i)*b(j)+c
108 LET c=INT (q/10)
110 LET p(i+j-1)=q-c*10+p(i+j-1)
112 LET d=INT (p(i+j-1)/10)
114 LET c=c+d
116 LET p(i+j-1)=p(i+j-1)-10*d
118 NEXT j
120 LET p(i+n)=c
122 NEXT i
130 PRINT "Product is:"
132 FOR i=k TO 1 STEP -1
134 IF (i=k) AND (p(i)=0) THEN GO TO 138
136 PRINT p(i);
138 NEXT i
140 STOP

R.A.Schrack

Give number of digits in terms 1
 and 2 :30 and 41

Give digits of first term
241573142393627673576957439049

Give digits of second term
45994811347886846310221728895223
034301839

Product is:
11111111111111111111111111111111
11111111111111111111111111111111
1111111

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.