Pascal's triangle: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: removed ''height'' from ''style''. -- ~~~~)
m (→‎{{header|REXX}}: added comments in the header section about creating a disk file vs. displaying the triangle. -- ~~~~)
Line 1,961: Line 1,961:


=={{header|REXX}}==
=={{header|REXX}}==
There is no pratical limit for this version, triangles up to 46 lines have been generated in a
There is no pratical limit for this version, triangles up to 46 rows have been generated in a
<br>window 620 pixels wide.
<br>window 620 pixels wide.
<br><br>If the number specified is negative, the output is written to a file instead. Triangles up to
<br>1000 rows have been created. The file created is named: '''PASCALS.n'''
<br>where '''n''' is the absolute value of the number entered.
<lang rexx>/*REXX program to display Pascal's triangle, neatly centered/formatted.*/
<lang rexx>/*REXX program to display Pascal's triangle, neatly centered/formatted.*/
/*AKA: Yang Hui's ▲, Khayyam-Pascal ▲, Kyayyam ▲, Tartaglia's ▲ */
/*AKA: Yang Hui's ▲, Khayyam-Pascal ▲, Kyayyam ▲, Tartaglia's ▲ */
numeric digits 300 /*let's be able to handle big ▲. */
numeric digits 1000 /*let's be able to handle big ▲. */
arg n .; if n=='' then n=10
arg nn .; if nn=='' then nn=10; n=abs(nn)
a.=1 /*if NN < 0, output is to a file.*/
if n<1 then do; say "***error!*** N can't be non-positive:" n; exit 13;end
mx=!(n-1) / !(n%2) / !(n-1-n%2) /*MX =biggest number in triangle.*/
a.=1
mx=!(n-1)/!(n%2)/!(n-1-n%2) /*MX =biggest number in triangle.*/
w=length(mx) /* W =width of biggest number. */
w=length(mx) /* W =width of biggest number. */
line.=1
line.=1
Line 1,986: Line 1,988:


do L=1 for n /*show lines in Pascal's triangle*/
do L=1 for n /*show lines in Pascal's triangle*/
say center(line.L,width)
if nn>0 then say center(line.L,width) /*either SAY or write.*/
else call lineout 'PASCALS.'n,center(line.L,width)
end /*L*/
end /*L*/
exit
exit