Anonymous user
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 */
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 '
box.0.j=_ /*build top label cell. */
box.j.0=_ /*build left label cell. */
end
box.0.0=centre('
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.*/
if row==0 then do
asep=overlay(trc,asep,sepL) /*make a better trc.*/
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
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">
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│times│ 1x │ 2x │ 3x │ 4x │ 5x │ 6x │ 7x │ 8x │ 9x │ 10x │ 11x │ 12x │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 12x │ │ │ │ │ │ │ │ │ │ │ │ 144 │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
</pre>
<lang rexx>
Below is another output when a
10
is specified as the program's argument.
</lang>
|