Matrices and grids · 7 / 15 Exercise Easy

Transpose a matrix

Objective

The transpose of a matrix swaps rows and columns: the element at row i and column j moves to row j and column i.

Instructions

  • The first line has the number of rows f and columns c; then come f lines with the values separated by spaces.
  • Show the transposed matrix, one row per line and with the values separated by spaces.
Input
2 3
1 2 3
4 5 6
Output
1 4
2 5
3 6

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise