Multiplication tables: Difference between revisions

(Remove duplicates of BASIC implementations after copying into one BASIC section.)
(→‎{{header|Commodore BASIC}}: Add implementation)
Line 1,507:
12 144</pre>
 
==={{header|Commodore BASIC}}===
The table consumes every one of the 1000 cells in a 40-column display, and even so has to cheat a little to fit 10x10=100 into the table. It uses the INSERT character (<tt>CHR$(148)</tt>) to push characters over to the right after printing them without triggering a scroll that would push the top line off the screen.
<lang gwbasic>100 PRINT CHR$(14);CHR$(147);
110 PRINT " X";
120 W=2
130 FOR I=1 TO 10
140 : N=I
150 : GOSUB 520
160 : PRINT ":"N$;
170 NEXT I
180 W=3
190 FOR I=11 TO 12
200 : N=I
210 : GOSUB 520
220 : PRINT ":"N$;
230 NEXT
240 FOR I=1 TO 12
250 : PRINT "--";
260 : FOR J=1 TO 10
270 : PRINT "+--";
280 : NEXT J
290 : FOR J=11 TO 12
300 : PRINT "+---";
310 : NEXT J
320 : N=I:W=2:GOSUB 520:PRINT N$;
330 : FOR J=1 TO 10
340 : W=2
350 : IF J<I THEN N$=" ":GOSUB 530:GOTO 370
360 : N=I*J:GOSUB 520
370 : IF LEN(N$)<3 THEN PRINT ":";
380 : PRINT N$;
390 : NEXT J
400 : FOR J=11 TO 12
410 : W=3
420 : IF J<I THEN N$=" ":GOSUB 530:GOTO 440
430 : N=I*J:GOSUB 520
440 : PRINT N$;
450 : FOR K=1 TO LEN(N$): PRINT CHR$(157);:NEXT K
460 : PRINT CHR$(148);":";
470 : IF J<12 THEN FOR K=1 TO LEN(N$):PRINT CHR$(29);: NEXT K
480 : NEXT J: IF I<12 THEN PRINT
490 NEXT I
500 GET K$: IF K$="" THEN 500
510 END
520 N$=MID$(STR$(N),2)
530 IF LEN(N$)<W THEN N$=" "+N$:GOTO 530
540 RETURN</lang>
 
{{Out}}
<pre> x: 1: 2: 3: 4: 5: 6: 7: 8: 9:10: 11: 12
--+--+--+--+--+--+--+--+--+--+--+---+---
1: 1: 2: 3: 4: 5: 6: 7: 8: 9:10: 11: 12
--+--+--+--+--+--+--+--+--+--+--+---+---
2: : 4: 6: 8:10:12:14:16:18:20: 22: 24
--+--+--+--+--+--+--+--+--+--+--+---+---
3: : : 9:12:15:18:21:24:27:30: 33: 36
--+--+--+--+--+--+--+--+--+--+--+---+---
4: : : :16:20:24:28:32:36:40: 44: 48
--+--+--+--+--+--+--+--+--+--+--+---+---
5: : : : :25:30:35:40:45:50: 55: 60
--+--+--+--+--+--+--+--+--+--+--+---+---
6: : : : : :36:42:48:54:60: 66: 72
--+--+--+--+--+--+--+--+--+--+--+---+---
7: : : : : : :49:56:63:70: 77: 84
--+--+--+--+--+--+--+--+--+--+--+---+---
8: : : : : : : :64:72:80: 88: 96
--+--+--+--+--+--+--+--+--+--+--+---+---
9: : : : : : : : :81:90: 99:108
--+--+--+--+--+--+--+--+--+--+--+---+---
10: : : : : : : : : 100:110:120
--+--+--+--+--+--+--+--+--+--+--+---+---
11: : : : : : : : : : :121:132
--+--+--+--+--+--+--+--+--+--+--+---+---
12: : : : : : : : : : : :144</pre>
==={{header|FreeBASIC}}===
<lang freebasic>
1,480

edits