#K70972. Spiral Matrix Generation
Spiral Matrix Generation
Spiral Matrix Generation
Given an integer \(n\), generate a \(n \times n\) matrix filled with the numbers from \(1\) to \(n^2\) in spiral order. The spiral starts from the top-left corner and proceeds to the right, then down, left, and up, continuing inwards.
For example, when \(n = 3\), the output should be:
1 2 3 8 9 4 7 6 5
Follow the input and output format as described below.
inputFormat
The input consists of a single integer \(n\) (\(1 \leq n \leq 100\)), which represents the size of the matrix.
The input is provided via standard input.
outputFormat
Output the generated \(n \times n\) matrix, where each row is printed on a new line and the numbers in each row are separated by a single space.
The output must be sent to standard output.
## sample1
1