#C8089. Spiral Matrix Generation
Spiral Matrix Generation
Spiral Matrix Generation
Given an integer \( n \), generate an \( n \times n \) spiral matrix. The matrix should be filled with the integers from \( 1 \) to \( n^2 \) in a clockwise spiral order, starting from the top-left corner and moving inward.
Example:
Input: 3 Output: 1 2 3 8 9 4 7 6 5
Your program should read the input from stdin
and print the spiral matrix to stdout
, where each row is printed on a new line and the numbers in each row are separated by a space.
Note: All formulas are formatted in LaTeX. For example, \( n^2 \) represents "n squared."
inputFormat
The input consists of a single integer \( n \) on one line, representing the size of the matrix.
outputFormat
The output is the \( n \times n \) spiral matrix printed to stdout. Each row of the matrix should be printed on a separate line with the numbers separated by a single space.
## sample1
1