For example, 3 × 3 cube Arrays: 816357492 cube arrays are arranged as follows: (1) Place 1 in the middle column of the first row; (2) the numbers starting from 2 until n × n are stored in sequence according to the following rules. The number of rows in each number is 1 less than the number of rows in the previous number, and the number of columns is 1 (for example, the third-level cube array above, 5); (3) if the number of rows in the previous row is 1
For example, the arrangement of the 3x3 cube array: 816 357 cube array is as follows: (1) Place 1 in the middle column of the first row; (2) the numbers starting from 2 until n × n are stored in sequence according to the following rules. The number of rows in each number is 1 less than the number of rows in the previous number, and the number of columns is 1 (for example, the third-level cube array above, 5); (3) if the number of rows in the previous row is 1
For example, a 3 × 3 cube array:
8 1 6
3 5 7
4 9 2
The arrangement rules of cube arrays are as follows:
(1) Place 1 in the middle column of the first row;
(2) The numbers starting from 2 until n × n are stored in sequence according to the following rules. The number of rows in each number is 1 less than the number of rows in the previous number, add 1 to the number of columns (for example, the third-level cube array above, and 5 to the last row and the last column of 4 );
(3) If the number of rows in the previous row is 1, the number of rows in the next row is n (the bottom row). For example, if 1 is in the first row, 2 should be placed in the bottom row, add 1 to the number of columns;
(4) when the number of columns in the previous row is n, the number of columns in the next row is 1, and the number of rows minus 1. For example, if 2 is in the last column of row 3rd, 3 should be placed in the first column of the Second row;
(5) If there is an existing number at the position specified by the preceding rule, or the previous number is the nth column of the first row, the next number is placed below the previous number. For example, according to the above rules, 4 should be placed in the 1st columns of the 2nd rows, but this position has been occupied, SO 4 should be placed below 3;
# Include
Int main ()
{
Int a [15] [15], I, j, k, p, n;
P = 1;
While (p = 1)
{
Printf ("enter n (n = 1--15 ):");
Scanf ("% d", & n );
If (n! = 0) & (n <= 15) & (n % 2! = 0 ))
P = 0;
}
For (I = 1; I <= n; I ++)
For (j = 1; j <= n; j ++)
A [I] [j] = 0;
J = n/2 + 1;
A [1] [j] = 1;
For (k = 2; k <= n * n; k ++)
{
I = I-1;
J = j + 1;
If (I <1 & j> n)
{
I = I + 2;
J = J-1;
}
Else
{
If (I <1) I = n;
If (j> n) j = 1;
}
If (a [I] [j] = 0)
A [I] [j] = k;
Else
{
I = I + 2;
J = J-1;
A [I] [j] = k;
}
}
For (I = 1; I <= n; I ++)
{
For (j = 1; j <= n; j ++)
Printf ("% 5d", a [I] [j]);
Puts ("");
}
Return 0;
}