Jump to content

Multiplication tables: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 1,487:
/*REXX program to display a 12x12 multiplication boxed grid table.*/
 
/*grid will be displayed in "boxing" characters for ASCII or EBCDIC */
high=12 /*the highest number in table*/
cell='+-----'/*computers. /*define the top of the cell.*/
 
sep=copies(cell,high+1)'+' /*build the table seperator. */
parse arg high . /*get optional grid size. */
if high=='' then high=12 /*not specified? Use default*/
 
ebcdic='f0'==1 /*is this an EBCDIC machine? */
 
if ebcdic then do /*----------EBCDIC-----------*/
bar='fa'x /*vertical bar. */
dash='bf'x /*horizontal dash. */
bj ='cb'x /*bottom junction. */
tj ='cc'x /* top junction. */
cj ='8f'x /*center junction (cross). */
lj ='eb'x /* left junction. */
rj ='ec'x /* right junction. */
tlc='ac'x /*top left corner. */
trc='bc'x /*top right corner. */
blc='ab'x /*bottom left corner. */
brc='bb'x /*bottom right corner. */
end
else do /*----------ASCII------------*/
bar='b3'x /*vertical bar. */
dash='c4'x /*horizontal dash. */
bj ='c1'x /*bottom junction. */
tj ='c2'x /* top junction. */
cj ='c5'x /*center junction (cross). */
lj ='c3'x /* left junction. */
rj ='b4'x /* right junction. */
tlc='da'x /*top left corner. */
trc='bf'x /*top right corner. */
blc='c0'x /*bottom left corner. */
brc='d9'x /*bottom right corner. */
end
 
cell=cj||copies(dash,5) /*define the top of the cell.*/
sep=copies(cell,high+1)rj /*build the table seperator. */
sepL=length(sep) /*length of seperator line. */
width=length(cell)-1 /*width of the table cells. */
size=width-1 /*width for table numbers. */
Line 1,496 ⟶ 1,531:
 
do j=0 to high /*step through zero to H (12)*/
_=right(j,size-1)'x ' /*build "label"/border number*/
box.0.j=_ /*build top label cell. */
box.j.0=_ /*build left label cell. */
end
 
box.0.0=centre('Xtimes',width) /*redefine box.0.0 with 'X' */
 
do row=1 for high /*step through 1 to H (12).*/
Line 1,512 ⟶ 1,547:
 
do row=0 to high /*step through all the lines.*/
say asep=sep /*displayallow ause tableof grida line.modified sep*/
 
w='' /*start with a blank cell. */
if row==0 then do
do col=0 to high /*step through 0 to H (12).*/
w=w'|'box.row.col asep=overlay(tlc,asep,1) /*buildmake onea cellbetter at a timetlc. */
asep=overlay(trc,asep,sepL) /*make a better trc.*/
end
say w'|' asep=translate(asep,tj,cj) /*finishmake buildinga lastbetter cell tj. */
end
else asep=overlay(lj,asep,1) /*make a better lj.*/
 
say asep /*display a table grid line. */
if row==0 then call buildLine 00 /*display a blank grid line. */
call buildLine row /*build one line of the grid.*/
if row==0 then call buildLine 00 /*display a blank grid line. */
end
 
say asep=sep /*displayallow ause tableof grida line.modified sep*/
asep=overlay(blc,asep,1) /*make a better bot left corn*/
asep=overlay(brc,asep,sepL) /*make a better bot right cor*/
asep=translate(asep,bj,cj) /*make a better bot junction.*/
say asep /*display a table grid line. */
say /*display a blank line. */
exit
 
 
buildLine: w='' /*start with a blank cell. */
parse arg arow
 
do col=0 to high /*step through 0 to H (12).*/
w=w||bar||box.arow.col /*build one cell at a time. */
end
 
say w||bar /*finish building last cell. */
return
</lang>
Output:
<pre style="height:30ex;overflow:scroll">
 
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| X | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | │ │ │ │
│times│ 1x │ 2x │ 3x │ 4x │ 5x │ 6x │ 7x │ 8x │ 9x │ 10x │ 11x │ 12x │
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | │ │ │ │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 1x 2 | 1 | 2 4 | 3 6 | 4 8 | 5 10 | 126 | 14 |7 16 | 8 18 | 209 | 2210 | 2411 │ 12 |
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 2x 3 | | 4 | 6 9 | 8 12 | 10 15 | 12 18 | 14 21 | 16 24 | 18 27 | 20 30 | 22 33 | 24 36 |
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 3x 4 | | | 9 |12 16 |15 20 |18 24 |21 28 |24 32 |27 36 |30 40 |33 44 | 4836 |
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 4x 5 | | | | 16 20 | 2524 | 3028 | 3532 | 4036 | 45 | 5040 | 5544 | 6048 |
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 5x 6 | | | | | 25 30 | 3635 | 4240 | 4845 | 5450 | 6055 | 66 | 7260 |
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 6x 7 | | | | | | 36 42 | 4948 | 5654 | 6360 | 7066 | 7772 | 84 |
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 7x 8 | | | | | | | 49 56 | 6463 | 7270 | 8077 | 8884 | 96 |
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 8x 9 | | | | | | | | 64 72 | 8180 | 9088 | 9996 | 108 |
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 109x | | | | | | | | | 81 |90 100 | 11099 | 120108 |
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 10x 11 | | | | | | | | | |100 110 120 | 121 | 132 |
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 11x 12 | | | | | | | | | | |121 132 | 144 |
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
│ 12x │ │ │ │ │ │ │ │ │ │ │ │ 144 │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
 
</pre>
<lang rexx>
Below is another output when a
 
<br>
10
<br>
10
<br>
<br>
is specified as the program's argument.
</lang>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.