Jump to content

Multiplication tables: Difference between revisions

m
→‎{{header|REXX}}: added/changed whitespace and comments, changed the 2nd output example.
m (→‎{{header|REXX}}: added/changed whitespace and comments, changed the 2nd output example.)
Line 2,895:
blc = '└' ; brc = '┘' /*bottom " " " " */
/* [↑] define stuff to hold box glyphs*/
cell = cj || copies(dash, 5) /*define the top of the cell. */
sep = copies(cell, high+1)rj /*buildconstruct the table separator. */
sepLL = length(sep) /*the length of the separator line. */
width= length(cell)-1 /*width of the table cells. */
size = width-1 /*width for the table numbers. products in the table. */
box. = left('', width) /*constructinitialize all the cells. in the table*/
 
do j=0 to high /*step through zero ───► high. */
_=right(j, size-1)'x ' /*build the "label" (border) number. */
box.0.j=_ /*build the " " top label cell. */
box.j.0=_ /*build the " " left label cell. */
end /*j*/
 
box.0.0=centre('times', width) /*redefineredefie box.0.0 with 'X' "times". */
 
do rowr=1 for high /*step through row one ───► high. */
do colc=rowr to high /*step through column row ───► high. */
box.rowr.colc=right(rowr*colc, size)' ' /*build a single multiplication cell. */
end /*colc*/
end /*rowr*/ /*only build the top right-half of grid*/
 
do rowr=0 to high; @=sep /*step through all the lines. ; use a mod sep*/
if rowr==0 then do
asep=sep /*allow use of a modified separator. */
asep@=translateoverlay(aseptlc,@ tj, ,cj1) /*makeuse a better tlc (top tj. left corner). */
if row==0 then do
asep@=overlay(tlctrc,@ asep, 1L) /* " " /*make" a better trc tlc.( " right " ). */
asep@=overlaytranslate(trc@, aseptj, sepLcj) /* " " /*make a better " trc. tj (top junction/tee).*/
end
asep=translate(asep, tj ,cj) /*make a better tj. */
else @=overlay(lj, @ ,1) end/* " " " lj (left junction/tee).*/
say @ else asep=overlay(lj, asep ,1) /*makedisplay a bettersingle table grid ljline. */
if r==0 then call buildLine 00 /* " " " blank grid " */
say asep call buildLine r /*displaybuild a table gridsingle line. of the grid. */
if r==0 then call buildLine 00 /*display a single blank grid line. */
end /*rowr*/
 
@=sep say asep /*displayallow use of a tablemodified grid lineseparator. */
@=overlay(blc, @ if, row==01) then call buildLine 00 /*display a blank grid line. /*use a better bottom left corner. */
@=overlay(brc, @ , L) call buildLine row /*build one" line of" the grid. " " right corner. */
@=translate(@, bj, cj) if row==0 then call buildLine 00 /*display a" blank grid" line. " " junction. */
say w@ || bar /*finish building the last cell. /*display a (single) table grid line. */
end /*row*/
 
asep=sep /*allow use of a modified separator. */
asep=overlay(blc, asep, 1) /*make a better bottom left corner. */
asep=overlay(brc, asep, sepL) /*make a better bottom right corner. */
asep=translate(asep, bj, cj) /*make a better bottom junction. */
say asep /*display a table grid line. */
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
buildLine: parse w=;arg row,,$ parse arg arow /*start with a blank cell. ($). */
do col=0 to high /*step through zero ───► high. */
 
do col$=0$ || tobar high|| box.row.col /*build one cell at a /*steptime. through zero ───► high. */
end w=w||bar||box.arow.col /*build one cell at a time. col*/
say $ || bar end /*colfinish building the last cell. */
say w || bar /*finish building the last cell. */
return</lang>
'''output''' &nbsp; when using the default input:
<pre>
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
Line 2,977 ⟶ 2,974:
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
</pre>
'''output''' &nbsp; when the following is used for input: &nbsp; <tt> 1016 </tt>
<pre>
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│times│ 1x │ 2x │ 3x │ 4x │ 5x │ 6x │ 7x │ 8x │ 9x │ 10x │ 11x │ 12x │ 13x │ 14x │ 15x │ 16x
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 1x │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │ 11 │ 12 │ 13 │ 14 │ 15 │ 16
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 2x │ │ 4 │ 6 │ 8 │ 10 │ 12 │ 14 │ 16 │ 18 │ 20 │ 22 │ 24 │ 26 │ 28 │ 30 │ 32
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 3x │ │ │ 9 │ 12 │ 15 │ 18 │ 21 │ 24 │ 27 │ 30 │ 33 │ 36 │ 39 │ 42 │ 45 │ 48
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 4x │ │ │ │ 16 │ 20 │ 24 │ 28 │ 32 │ 36 │ 40 │ 44 │ 48 │ 52 │ 56 │ 60 │ 64
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 5x │ │ │ │ │ 25 │ 30 │ 35 │ 40 │ 45 │ 50 │ 55 │ 60 │ 65 │ 70 │ 75 │ 80
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 6x │ │ │ │ │ │ 36 │ 42 │ 48 │ 54 │ 60 │ 66 │ 72 │ 78 │ 84 │ 90 │ 96
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 7x │ │ │ │ │ │ │ 49 │ 56 │ 63 │ 70 │ 77 │ 84 │ 91 │ 98 │ 105 │ 112
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 8x │ │ │ │ │ │ │ │ 64 │ 72 │ 80 │ 88 │ 96 │ 104 │ 112 │ 120 │ 128
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 9x │ │ │ │ │ │ │ │ │ 81 │ 90 │ 99 │ 108 │ 117 │ 126 │ 135 │ 144
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 10x │ │ │ │ │ │ │ │ │ │ 100 │ 110 │ 120 │ 130 │ 140 │ 150 │ 160
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
│ 11x │ │ │ │ │ │ │ │ │ │ │ 121 │ 132 │ 143 │ 154 │ 165 │ 176 │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 12x │ │ │ │ │ │ │ │ │ │ │ │ 144 │ 156 │ 168 │ 180 │ 192 │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 13x │ │ │ │ │ │ │ │ │ │ │ │ │ 169 │ 182 │ 195 │ 208 │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 14x │ │ │ │ │ │ │ │ │ │ │ │ │ │ 196 │ 210 │ 224 │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 15x │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 225 │ 240 │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ 16x │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 256 │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
</pre>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.