#C4434. Clockwise Spiral Matrix
Clockwise Spiral Matrix
Clockwise Spiral Matrix
Given a positive integer \(n\), generate an \(n \times n\) matrix filled with the numbers from 1 to \(n^2\) arranged in a clockwise spiral order. If \(n \le 0\), output an empty matrix.
The spiral starts at the top-left corner and proceeds towards the right, then down, then left, and then up repeatedly until the matrix is filled.
For example, when \(n = 3\), the resulting matrix is:
1 2 3 8 9 4 7 6 5
inputFormat
The input consists of a single integer \(n\) provided via standard input (stdin). This integer represents the size of the matrix.
Constraints:
- \(n\) is an integer and may be non-positive. In that case, an empty matrix should be returned.
outputFormat
Output the generated matrix to standard output (stdout). Each row of the matrix should be printed on a new line and the elements in each row should be separated by a single space. If the matrix is empty, output nothing.
## sample3
1 2 3
8 9 4
7 6 5
</p>