Multiplication tables: Difference between revisions

Content added Content deleted
No edit summary
No edit summary
Line 1,487: Line 1,487:
/*REXX program to display a 12x12 multiplication boxed grid table.*/
/*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='+-----' /*define the top of the cell.*/
/*computers. */

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. */
width=length(cell)-1 /*width of the table cells. */
size=width-1 /*width for table numbers. */
size=width-1 /*width for table numbers. */
Line 1,496: Line 1,531:


do j=0 to high /*step through zero to H (12)*/
do j=0 to high /*step through zero to H (12)*/
_=right(j,size)' ' /*build "label"/border number*/
_=right(j,size-1)'x ' /*build "label"/border number*/
box.0.j=_ /*build top label cell. */
box.0.j=_ /*build top label cell. */
box.j.0=_ /*build left label cell. */
box.j.0=_ /*build left label cell. */
end
end


box.0.0=centre('X',width) /*redefine box.0.0 with 'X' */
box.0.0=centre('times',width) /*redefine box.0.0 with 'X' */


do row=1 for high /*step through 1 to H (12).*/
do row=1 for high /*step through 1 to H (12).*/
Line 1,512: Line 1,547:


do row=0 to high /*step through all the lines.*/
do row=0 to high /*step through all the lines.*/
say sep /*display a table grid line. */
asep=sep /*allow use of a 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 /*build one cell at a time. */
asep=overlay(tlc,asep,1) /*make a better tlc.*/
asep=overlay(trc,asep,sepL) /*make a better trc.*/
end
say w'|' /*finish building last cell. */
asep=translate(asep,tj,cj) /*make a better 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
end


say sep /*display a table grid line. */
asep=sep /*allow use of a 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. */
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>
</lang>
Output:
Output:
<pre style="height:30ex;overflow:scroll">
<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 |
│ │ │ │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 2 | | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 |
1x 1 2 3 4 5 6 7 8 9 10 11 │ 12
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 3 | | | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 | 33 | 36 |
2x 4 6 8 10 12 14 16 18 20 22 24
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 4 | | | | 16 | 20 | 24 | 28 | 32 | 36 | 40 | 44 | 48 |
3x 9 12 15 18 21 24 27 30 33 36
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 5 | | | | | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 |
4x 16 20 24 28 32 36 40 44 48
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 6 | | | | | | 36 | 42 | 48 | 54 | 60 | 66 | 72 |
5x 25 30 35 40 45 50 55 60
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 7 | | | | | | | 49 | 56 | 63 | 70 | 77 | 84 |
6x 36 42 48 54 60 66 72
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 8 | | | | | | | | 64 | 72 | 80 | 88 | 96 |
7x 49 56 63 70 77 84
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 9 | | | | | | | | | 81 | 90 | 99 | 108 |
8x 64 72 80 88 96
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 10 | | | | | | | | | | 100 | 110 | 120 |
9x 81 90 99 108
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 11 | | | | | | | | | | | 121 | 132 |
10x 100 110 120
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 12 | | | | | | | | | | | | 144 |
11x 121 132
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
│ 12x │ │ │ │ │ │ │ │ │ │ │ │ 144 │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘


</pre>
</pre>
<lang rexx>
<lang rexx>
Below is another output when a
Below is another output when a

<br>
10
<br>
10
<br>
<br>
is specified as the program's argument.
is specified as the program's argument.
</lang>
</lang>