Matrices and grids · 8 / 15 Exercise Medium

Rotate a matrix 90 degrees

Objective

Rotating a matrix 90° clockwise is equivalent to reversing the order of the rows and transposing. After rotating, a matrix of f rows and c columns has c rows and f columns.

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 matrix rotated 90° clockwise.
Input
2 3
1 2 3
4 5 6
Output
4 1
5 2
6 3

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

Start exercise