Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Matrix-transposition/Icon/matrix-transposition.icon
Normal file
28
Task/Matrix-transposition/Icon/matrix-transposition.icon
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
procedure transpose_matrix (matrix)
|
||||
result := []
|
||||
# for each column
|
||||
every (i := 1 to *matrix[1]) do {
|
||||
col := []
|
||||
# extract the number in each row for that column
|
||||
every (row := !matrix) do put (col, row[i])
|
||||
# and push that column as a row in the result matrix
|
||||
put (result, col)
|
||||
}
|
||||
return result
|
||||
end
|
||||
|
||||
procedure print_matrix (matrix)
|
||||
every (row := !matrix) do {
|
||||
every writes (!row || " ")
|
||||
write ()
|
||||
}
|
||||
end
|
||||
|
||||
procedure main ()
|
||||
matrix := [[1,2,3],[4,5,6]]
|
||||
write ("Start:")
|
||||
print_matrix (matrix)
|
||||
transposed := transpose_matrix (matrix)
|
||||
write ("Transposed:")
|
||||
print_matrix (transposed)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue