#K2626. Spiral Matrix
Spiral Matrix
Spiral Matrix
Given a positive integer ( n ), print a square matrix of size ( n \times n ) filled with numbers from 1 to ( n^2 ) in clockwise spiral order. The matrix is constructed by filling the outer layer first and then moving inward. Each row of the matrix should be printed on a new line with its elements separated by a single space.
For example, when ( n = 3 ), the expected output is:
1 2 3
8 9 4
7 6 5
inputFormat
The input consists of a single integer ( n ) (where ( 1 \leq n \leq 100 )) read from standard input.
outputFormat
Output the ( n \times n ) spiral matrix with each row on a new line. Numbers in each row must be separated by a single space.## sample
1
1
</p>