Pascal's triangle: Difference between revisions

m
→‎{{header|REXX}}: added/changed comments and whitespace, simplified the code, changed wording in the REXX section header.
(added two variants)
m (→‎{{header|REXX}}: added/changed comments and whitespace, simplified the code, changed wording in the REXX section header.)
Line 4,582:
generated (without wrapping) in a screen window with a width of 620 characters.
 
If the number (of rows) specified is negative,   the output is written to a (disk) file
instead.   Triangles with over a   1,000   rows have easily been easily created.  
<br>The output file created (that is written to disk) is named &nbsp; &nbsp; '''PASCALS.n'''
&nbsp; &nbsp; where &nbsp; '''n''' &nbsp; is the absolute value of the number entered.
 
Line 4,597:
parse arg nn . /*obtain the optional argument from CL.*/
if nn=='' | nn=="," then nn= 10 /*Not specified? Then use the default.*/
Nn= abs(nn) /*N is the number of rows in triangle.*/
w= length( !(Nn-1) / % !(Nn%2) / % !(Nn - 1 -N n%2) ) /*W: the width of the biggest integer. */
ww= (n-1) * (W + 1) + 1 /*WW: " " " triangle's last row.*/
@.= 1; $.= @.; unity= right(1, w) /*defaults rows & lines; aligned unity.*/
/* [↓] build rows of Pascals' triangle*/
do r=1 for Nn; rm= r-1 /*Note: the first column is always 1.*/
do c=2 to rm; cm= c-1 /*build the rest of the columns in row.*/
@.r.c= @.rm.cm + @.rm.c /*assign value to a specific row & col.*/
$.r = $.r right(@.r.c, w) /*and construct a line for output (row)*/
end /*c*/ end /*c*/ /* [↑] C is the column being built.*/
if r\==1 then $.r= $.r unity /*for rows≥2, append a trailing "1".*/
end /*r*/ end /*r*/ /* [↑] R is the row being built.*/
/* [↑] WIDTH: for nicely looking line.*/
width= length($.N) do r=1 for n; $$= center($.r, ww) /*widthcenter ofthis theparticular lastPascals' (output)row. line (row)*/
/*if NN<0, output is written to a file.*/
do r=1 for N; $$= center($.r, width) /*center this particular Pascals' row. */
if nn>0 then say $$ /*SAY if NN is positive, else */
else call lineout 'PASCALS.'n, $$ /*write this Pascal's row ───► a file.*/
Line 4,617 ⟶ 4,616:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
!: procedure; !=1; do j=2 to arg(1); != !*j; end /*j*/; return ! /*compute factorial*/</lang>
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> 11 </tt>}}
<pre>