This odd number is a mathematical method, and it can be understood. It is more troublesome to describe it. A structural method: first set 1 at the center of the lower line of the entire matrix, then fill 2, 3, 4, 5, 6, 7, ... pay attention to the bottom of the bottom. Turn it to the top, turn to the left to go to the left, if 1 is filled in (5, 3), 2 should be filled in (1, 4), 4 should fill in At (3, 1) ... In addition, when there is already a number below, it is necessary to fill in the number of fills to the original number of 5 * 5 fantasy squares. When 5 is filled (4, 2) When the lower right is 1, the 6 cannot be filled there, but should be filled in (3, 2), that is, 5 above. Finally, a special point, the lower right corner, the new number should also be filled in the lower right corner. One of the illvolution of 5 * 5 is given: 11 18 25 2 910 12 19 21 34 6 13 20 22 23 5 7 14 1617 24 1 8 15
#include
INT A [MAX] = {0}; int N = 0;
Void Initial () {INT I, J; For (i = 0; i Void get () {INT i = 0, J; INT pre_i, pre_j; int K = 1; A [0] [N / 2] = K; i = 0; J = N / 2; for (k = 2; K <= n * n; k ) {pre_i = i; pre_j = j; I -; j ; if (pre_i == 0) {i = N-1;} if (pre_j == n-1) {J = 0;} IF (a [i] [j]! = 0) {i = pre_i; j = pre_j 1; a [i] [j] = k;} if (a [i] [j] == 0) {a [i] [j] = k;}}} Main () {INT I, J; CHAR flag = -1; while (1) {initial (); Printf ("please input the square of the massix: / n"); scanf ("% d", & n); Fflush (stdin); get (); for (i = 0; i