Matrix transposition: Difference between revisions

Content added Content deleted
(Added BBC BASIC)
m (→‎{{header|REXX}}: added comments, unrolled some DO loops, changed indentation, added whitespace. -- ~~~~)
Line 1,849: Line 1,849:
=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX program transposes a matrix, shows before and after matrixes. */
<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.1='1.02 2.03 3.04 4.05 5.06 6.07 7.07'
x.2='111 2222 33333 444444 5555555 66666666 777777777'
x.2='111 2222 33333 444444 5555555 66666666 777777777'


do r=1 while x.r\=='' /*build the "A" matric from X. numbers */
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
do c=1 while x.r\==''
parse var x.r a.r.c x.r
end
end /*c*/
end /*r*/


rows=r-1; cols=c-1
rows=r-1; cols=c-1
L=0 /*L is the maximum width element value.*/
L=0 /*L is the maximum width element value.*/
do i=1 for rows

do i=1 for rows
do j=1 for cols
do j=1 for cols
b.j.i = a.i.j; L=max(L,length(b.j.i))
b.j.i=a.i.j; L=max(L,length(b.j.i))
end /*j*/
end
end /*i*/
end


call showMat 'A',rows,cols
call showMat 'A',rows,cols
call showMat 'B',cols,rows
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
_=_ right(value(mat'.'r'.'c),L)
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
end /*r*/
return</lang>
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
1.02 2.03 3.04 4.05 5.06 6.07 7.07
111 2222 33333 444444 5555555 66666666 777777777
111 2222 33333 444444 5555555 66666666 777777777


────────B matrix────────
--------B matrix--------
1.02 111
1.02 111
2.03 2222
2.03 2222