Anonymous user
Matrix multiplication: Difference between revisions
m
→{{header|REXX}}: added/changed comments and whitespace, used a template for the output section.
(Add S-Lang) |
m (→{{header|REXX}}: added/changed comments and whitespace, used a template for the output section.) |
||
Line 3,925:
=={{header|REXX}}==
<lang rexx>/*REXX program multiplies two matrices together, displays the matrices and the results. */
x.=; x.1= 1 2
x.2= 3 4
x.3= 5 6
x.4= 7 8
do r=1 while x.r\=='' /*build the "A" matrix from X. numbers.*/
do c=1 while x.r\==''; parse var x.r a.r.c x.r; end /*c*/
end /*r*/
Arows= r -
Acols= c -
y.=; y.1= 1 2 3
y.2= 4 5 6
do r=1 while y.r\=='' /*build the "B" matrix from Y. numbers.*/
do c=1 while y.r\==''; parse var y.r b.r.c y.r; end /*c*/
end /*r*/
Brows= r -
Bcols= c -
c.=
end /*k*/ /*
end
call showMatrix 'A', Arows, Acols /*display matrix A ───► the terminal.*/
Line 3,955 ⟶ 3,954:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
showMatrix: parse arg mat,rows,cols; say; say center(mat 'matrix', cols*(w+1) +
do r=1 for rows; _= ' '
do c=1 for cols; _=_ right(value(mat'.'r"."c), w); end; say _
end /*r*/
return</lang>
{{out|output|text= when using the internal default input:}}
<pre>
───A matrix────
1 2
3 4
5 6
7 8
─────B matrix─────
1 2 3
4 5 6
─────C matrix─────
9 12 15
</pre>
|