Anonymous user
Multiplication tables: Difference between revisions
m
→{{header|REXX}}: simplified the code, add/changed comments and whitespace.
(→{{header|Visual Basic}}: fixed <pre> tag) |
m (→{{header|REXX}}: simplified the code, add/changed comments and whitespace.) |
||
Line 3,335:
=={{header|REXX}}==
A lot of the program code deals with the presentation/display of the grid for the multiplication
<lang REXX>/*REXX program displays a
parse arg high . /*
if high=='' | high=="," then high=12
bar = '│' ; dash =
bj = '┴' ; tj =
cj = '┼' /*center junction (or cross). */
lj = '├' ; rj =
tlc = '┌' ; trc =
blc = '└' ; brc =
/* [↑] define stuff to hold box glyphs*/
cell = cj || copies(dash,
sep = copies(cell, high+1)rj /*construct the table separator. */
do j=0 to high /*step through zero ───► high. */
_=right(j, size -
box.0.j=center(_,
box.j.0=center(_, max(5, size)
end /*j*/
box.0.0=
do r=1 for high /*step through row one ───► high. */
do c=r to high /*step through column row ───► high. */
box.r.c=right(r*c, size)
end /*c*/
end /*r*/ /*only build the top right-half of grid*/
do r=0 to high; @=sep /*step through all lines; use a mod sep*/
if r==0 then do
@=overlay(tlc, @ , 1) /*use a better tlc (top left corner). */
@=overlay(trc, @ ,
@=translate(@, tj, cj) /* " " " tj (top junction/tee).*/
end
else @=overlay(lj, @
say @ /*display a single table grid line. */
if r==0 then call buildLine 00 /* " " " blank grid " */
call buildLine r /*build a single line of the grid. */
if r==0 then call buildLine 00 /*display a single blank grid line. */
end /*r*/
@=sep /*allow use of a modified separator. */
@=overlay(blc, @ , 1) /*use a better bottom left corner. */
@=overlay(brc, @ ,
@=translate(@, bj, cj) /* " " " " junction. */
say @ /*display a (single) table grid line. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
buildLine: parse arg row,,$ /*start with a blank cell ($).
do col=0 to high /*step through zero
$=$ || bar || box.row.col /*build one cell at a time.
end /*col*/
say $ || bar /*finish building the last cell.
return</lang>
'''output''' when using the default input:
<pre>
|