Multiplication tables: Difference between revisions

m
→‎{{header|REXX}}: added DO-END labels, added comments, added whitespace. -- ~~~~
m (→‎{{header|F#}}: header cleanup)
m (→‎{{header|REXX}}: added DO-END labels, added comments, added whitespace. -- ~~~~)
Line 1,971:
 
=={{header|REXX}}==
<lang REXX>/*REXX program to displaydisplays a 12x12 multiplication boxed grid table., grid */
/*grid will be displayed in "boxing" characters for ASCII or EBCDIC .*/
parse arg high . rj ='ec'x /*get rightoptional junctiongrid size. */
if high=='' then high=12 /*not specified? Use default. */
box.0.jebcdic=_ 'f0'==1 /*buildis this topan labelEBCDIC cell.machine? */
 
if ebcdic then do /*══════════EBCDIC═══════════════*/
/*grid will be displayed in "boxing" characters for ASCII or EBCDIC */
/*computers. bar='fa'x /*vertical bar. */
tj dash='ccbf'x /*horizontal dash. top junction. */
 
parse arg high . bj ='cb'x /*getbottom junction. optional grid size. */
if high= tj ='cc' then high=12x /*not specified? Usetop junction. default*/
cj ='8f'x /*center junction (cross). */
 
ebcdic lj ='f0eb'==1x /* left junction. /*is this an EBCDIC machine? */
ljrj ='ebec'x /* leftright junction. */
 
if ebcdic then do tlc='ac'x /*----------EBCDIC-----------top left corner. */
bartrc='fabc'x /*verticaltop bar. right corner. */
dashblc='bfab'x /*horizontalbottom left dashcorner. */
bj brc='cbbb'x /*bottom junctionright corner. */
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------------══════════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 separator. */
sepL=length(sep) /*length of separator line. */
width=length(cell)-1 /*width of the table cells. */
size=width-1 /*width for table numbers. */
box.=left('',width) /*construct all the cells. */
 
box.=left('',width) /*construct all cells. */
 
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('times',width) /*redefine box.0.0 with 'X' */
 
do rowj=10 forto high /*step through 1 zero to H (12). */
do col_=row to highright(j,size-1)'x ' /*stepbuild through"label"/border rownumber. to H (12).*/
box.row0.colj=right(row*col,size)'_ ' /*build a multiplicationtop label cell. */
box.j.0=_ tlc='ac'x /*topbuild left label cell. left corner. */
end
end /*j*/
 
say box.0.0=centre('times',width) /*displayredefine a blank linebox.0.0 with 'X'. */
 
do row=0 to high do row=1 for high /*step through all the1 lines to H (12). */
asep=sep do col=row to high /*step through row to H (12). /*allow use of a modified sep*/
_ box.row.col=right(jrow*col,size-1)'x ' /*build "label"/bordera mult. cell. number*/
end /*col*/
end /*row*/
 
do jrow=0 to high /*step through zeroall the lines. to H (12)*/
asep=sep trc='bc'x /*topallow use of a rightmodified cornersep. */
if row==0 then do
asep=overlay(tlc,asep,1) /*make a better tlc. */
asep=overlay(trc,asep,sepL) /*make a better trc. */
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 /*row*/
 
asep=sep /*allow use of a modified sep. */
asep=overlay(blc,asep,1) /*make a better bot left corncorner.*/
asep=overlay(brc,asep,sepL) /*make a better bot right corcorner.*/
asep=translate(asep,bj,cj) /*make a better bot junction. */
say asep /*display a table grid line. */
say exit /*displaystick a blank line. fork in it, we're done.*/
/*──────────────────────────────────BUILDLINE subroutine────────────────*/
exit
buildLine: w=; parse arg arow /*start with a blank cell. */
 
brcdo col='bb'x0 to high /*step through 0 /*bottomto right cornerH (12). */
 
buildLine: w='' w=w||bar||box.arow.col /*build one cell at a time. /*start with a blank cell. */
end /*col*/
parse arg arow
say w || bar blc='ab'x /*bottomfinish building leftthe cornerlast cell. */
 
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:30ex50ex;overflow:scroll">
 
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│ │ │ │ │ │ │ │ │ │ │ │ │ │
Line 2,098 ⟶ 2,085:
│ 12x │ │ │ │ │ │ │ │ │ │ │ │ 144 │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
 
</pre>
'''output''' when the following is used for input: <tt> 10 </tt>
<lang rexx>
<pre style="height:30ex50ex;overflow:scroll">
Below is another output when a
 
10
is specified as the program's argument.
</lang>
Output:
<pre style="height:30ex;overflow:scroll">
 
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│ │ │ │ │ │ │ │ │ │ │ │
Line 2,135 ⟶ 2,113:
│ 10x │ │ │ │ │ │ │ │ │ │ 100 │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
 
</pre>