THE CHALLENGEPrint the numbers 1 to n*n arranged in a clockwise spiral that starts at the top-left corner, as an n x n grid. For n = 3:
1 2 3
8 9 4
7 6 5
Each number is printed right-aligned in a field of width 3 (%3d), with a newline after every row.
The challenge: no arrays. Work out each cell's value from its position (i, j) alone. Its ring is l = min(i, j, n-1-i, n-1-j); the numbers before that ring number n*n - (n - 2l)*(n - 2l); then walk along the ring's top, right, bottom and left sides.
Read n (1 to 9). Use nested for loops.
Sample input:
3
Sample output:
1 2 3
8 9 4
7 6 5