Addition Through 7 Digits

Developer(s): Francis LeBaron
Date: 1981
Type: Program
Platform(s): ZX80

The 4K ZX80 handles whole numbers only up to 32767. This program keeps a running total of seven digits, one digit per array element, and does the carrying itself. Enter a number of up to seven digits and press NEWLINE; enter another and the running total appears. As printed, zeros show only as spaces, and a carry is not added correctly.

In the March 1981 issue the author added line 225 LET FL=1, which prints zeros inside numbers, and corrected line 140 to LET Y(I+1)=Y(I+1)+1. The download has both versions. The printed Syntactic Sum of the original, 28812, lost its minus sign: the listing sums to -28812. Line 150 jumps to line 95, which does not exist.

Published in Syntax February 1981 (Addition Through 7 Digits).

Related Articles

Add 7 digit numbers as long as the total doesn't exceed 7 digits.

Related Content

Image Gallery

Source Code

  5 DIM X(7)
  7 DIM Y(7)
 10 INPUT A$
 20 FOR N=1 TO 7
 30 LET X(N)=CODE(A$)-28
 35 IF X(N)<0 THEN GO TO 70
 37 IF X(N)>9 THEN STOP
 50 LET A$=TL$(A$)
 60 NEXT N
 70 LET M=N-1
 80 FOR I=1 TO N-1
 90 LET Y(I)=Y(I)+X(M)
 97 IF Y(I)>9 THEN GO TO 130
100 LET M=M-1
110 NEXT I
120 GO TO 200
130 LET Y(I)=Y(I)-10
140 LET Y(I+1)=Y(I)+1
150 GO TO 95
200 LET M=7
202 LET FL=0
210 FOR I=1 TO 7
212 IF FL>0 THEN GO TO 220
214 IF Y(M)=0 THEN GO TO 260
215 LET FL=0
220 PRINT Y(M);
230 LET M=M-1
240 NEXT I
245 PRINT
250 GO TO 10
260 PRINT " ";
270 GO TO 230

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