#K43302. Matrix Rotation – Rotate a Matrix 90° Clockwise
Matrix Rotation – Rotate a Matrix 90° Clockwise
Matrix Rotation – Rotate a Matrix 90° Clockwise
You are given a square matrix of size \( n \times n \). Your task is to rotate the matrix by 90° clockwise.
The element at position \( (i, j) \) in the original matrix will be moved to position \( (j, n-1-i) \) in the rotated matrix. More formally, if \( A \) is the original matrix and \( B \) is the rotated matrix, then:
[ B_{j, n-1-i} = A_{i,j} ]
Print the resulting matrix, where each row is printed on a new line and the elements in a row are separated by a single space.
Input Format: The first line contains an integer \( n \), representing the dimension of the matrix. Each of the next \( n \) lines contains \( n \) integers separated by spaces.
Output Format: Output the rotated matrix with each row printed on a new line and elements separated by a space.
Make sure your solution reads input from standard input (stdin) and prints the output to standard output (stdout).
inputFormat
The first line contains a single integer \( n \) indicating the size of the square matrix. The next \( n \) lines each contain \( n \) integers separated by spaces representing the rows of the matrix.
outputFormat
Output the rotated matrix after a 90° clockwise rotation. Each row of the matrix should be printed on a new line, and the integers in each row are separated by a single space.
## sample3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
</p>