Matrix transposition: Difference between revisions

m
→‎{{header|REXX}}: added comments, unrolled some DO loops, changed indentation, added whitespace. -- ~~~~
(Added BBC BASIC)
m (→‎{{header|REXX}}: added comments, unrolled some DO loops, changed indentation, added whitespace. -- ~~~~)
Line 1,849:
=={{header|REXX}}==
<lang rexx>/*REXX program transposes a matrix, shows before and after matrixes. */
x.=''
 
x.=''
x.1='1.02 2.03 3.04 4.05 5.06 6.07 7.07'
x.2='111 2222 33333 444444 5555555 66666666 777777777'
 
do r=1 while x.r\=='' /*build the "A" matric from X. numbers */
do c=1 while x.r\==''; parse var x.r a.r.c x.r; end
parse var x.r a.r.c x.r
end
end /*c*/
end /*r*/
 
rows=r-1; cols=c-1
L=0 /*L is the maximum width element value.*/
do i=1 for rows
 
do ij=1 for rowscols
b.j.i = do a.i.j=1; for cols L=max(L,length(b.j.i))
end b./*j.i=a.i.j; L=max(L,length(b.j.i))*/
end end/*i*/
end
 
call showMat 'A',rows,cols
call showMat 'B',cols,rows
exit /*stick a fork in it, we're done.*/
exit
/*─────────────────────────────────────SHOWMAT subroutine───────────────*/
showMat: parse arg mat,rows,cols; say
say center(mat 'matrix', cols*(L+1)+4, "-")
 
do r=1 for rows; _=
/*─────────────────────────────────────SHOWMAT subroutine───────────────*/
do c=1 for cols;
showMat: parse arg mat,rows,cols; say
_=''; do c=1 for cols; _=_ right(value(mat'.'r'.'c),L); end; say _
say center(mat 'matrix',cols*(L+1)+4,"-")
do r=1 for rows end /*c*/
say _
_=''; do c=1 for cols; _=_ right(value(mat'.'r'.'c),L); end; say _
end /*r*/
return</lang>
'''output'''
Output:
<pre style="overflow:scroll">
<pre>
─────────────────────────────────A matrix─────────────────────────────────
---------------------------------A matrix---------------------------------
1.02 2.03 3.04 4.05 5.06 6.07 7.07
111 2222 33333 444444 5555555 66666666 777777777
 
────────B matrix────────
--------B matrix--------
1.02 111
2.03 2222