Pascal's triangle: Difference between revisions
Content deleted Content added
PatGarrett (talk | contribs) →{{header|360 Assembly}}: Section added |
PatGarrett (talk | contribs) →{{header|360 Assembly}}: Section added |
||
Line 11: | Line 11: | ||
'''See also:''' |
'''See also:''' |
||
* [[Evaluate binomial coefficients]] |
* [[Evaluate binomial coefficients]] |
||
=={{header|360 Assembly}}== |
|||
{{trans|PL/I}} |
|||
<lang 360asm> |
|||
* Pascal's triangle 25/10/2015 |
|||
PASCAL CSECT |
|||
USING PASCAL,R15 set base register |
|||
LA R7,1 n=1 |
|||
LOOPN C R7,=A(M) do n=1 to m |
|||
BH ELOOPN if n>m then goto |
|||
MVC U,=F'1' u(1)=1 |
|||
LA R6,1 i=1 |
|||
LOOPI1 CR R6,R7 do i=1 to n |
|||
BH ELOOPI1 if i>n then goto |
|||
LR R1,R6 i |
|||
SLA R1,2 i*4 |
|||
L R3,T-4(R1) t(i) |
|||
L R4,T(R1) t(i+1) |
|||
AR R3,R4 t(i)+t(i+1) |
|||
ST R3,U(R1) u(i+1)=t(i)+t(i+1) |
|||
LA R6,1(R6) i=i+1 |
|||
B LOOPI1 end i |
|||
ELOOPI1 LA R8,PG pgi=@pg |
|||
LA R6,1 i=1 |
|||
LOOPI2 CR R6,R7 do i=1 to n |
|||
BH ELOOPI2 if i>n then goto |
|||
LR R1,R6 i |
|||
SLA R1,2 i*4 |
|||
L R2,U-4(R1) u(i) |
|||
XDECO R2,XD edit u(i) |
|||
MVC 0(4,R8),XD+8 output u(i):4 |
|||
LA R8,4(R8) pgi=pgi+4 |
|||
LA R6,1(R6) i=i+1 |
|||
B LOOPI2 end i |
|||
ELOOPI2 MVC T((M+1)*(L'T)),U t=u |
|||
XPRNT PG,80 print |
|||
LA R7,1(R7) n=n+1 |
|||
B LOOPN end n |
|||
ELOOPN XR R15,R15 set return code |
|||
BR R14 return to caller |
|||
M EQU 11 <== input |
|||
T DC (M+1)F'0' t(m+1) init 0 |
|||
U DC (M+1)F'0' u(m+1) init 0 |
|||
PG DC CL80' ' pg init ' ' |
|||
XD DS CL12 temp |
|||
YREGS |
|||
END PASCAL |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
1 |
|||
1 1 |
|||
1 2 1 |
|||
1 3 3 1 |
|||
1 4 6 4 1 |
|||
1 5 10 10 5 1 |
|||
1 6 15 20 15 6 1 |
|||
1 7 21 35 35 21 7 1 |
|||
1 8 28 56 70 56 28 8 1 |
|||
1 9 36 84 126 126 84 36 9 1 |
|||
1 10 45 120 210 252 210 120 45 10 1 |
|||
</pre> |
|||