#K61297. Spiral Matrix Generator
Spiral Matrix Generator
Spiral Matrix Generator
Given an integer \( n \), generate an \( n \times n \) spiral matrix filled with numbers from 1 to \( n^2 \) in spiral order. The spiral is formed by starting at the top-left corner and moving right, then proceeding downwards, leftwards, and upwards in layers until the matrix is filled. For \( n \le 0 \), the output should be empty.
The task is to print the resulting matrix where each row is printed on a new line and the numbers in each row are separated by a single space.
inputFormat
A single integer ( n ) provided via standard input.
outputFormat
Print the ( n \times n ) spiral matrix. Each row of the matrix should be printed on a new line with each number separated by a single space. If ( n \le 0 ), no output should be produced.## sample
3
1 2 3
8 9 4
7 6 5
</p>