// Huangfang. CPP: defines the entry point for the console application. // # include "stdafx. H "Void setvalue (unsigned char * HF, int howmuch, int X, int y, unsigned char value) {// fill in the magic square matrix * (HF + (Y-1) * howmuch + (X-1) = value;} unsigned char getvalue (unsigned char * HF, int howmuch, int X, int y) {// fill in the Magic Square Matrix return * (HF + (Y-1) * howmuch + (X-1);} int printhf (INT howmuch) {If (howmuch> 9) // too many will not consider {return 1;} If (! (Howmuch % 2) // only {return 1;} unsigned char Buf [100] = ""; // 100 is enough, equivalent to 10x10 int I, j; int X, Y; for (I = 1; I <= howmuch * howmuch; I ++) {if (1 = I) {// first, of course, one in the middle of X, Y is the first line x = (howmuch/2) + 1; y = 1; setvalue (BUF, howmuch, X, y, I) ;}else {If (x = howmuch + 1 & 0 = y) {// X --; y ++;} in the upper right corner ;} if (Y <1) {// It is out of bounds and should be transferred to the bottom y = howmuch;} If (x> howmuch) {// It is out of bounds to the right, should be switched to leftmost x = 1;} If (getvalue (BUF, Howmuch, x, y) {// if this position has been added, use the next X --; y ++;} setvalue (BUF, howmuch, X, y, I);} // after filling in, X ++, y --, steps up to the upper right corner, X ++; y --;} for (I = 0; I
8 1 6 3 5 7 4 9 2 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 30 39 48 1 10 19 28 38 47 7 9 18 27 29 46 6 8 17 26 35 37 5 14 16 25 34 36 45 13 15 24 33 42 44 4 21 23 32 41 43 3 12 22 31 40 49 2 11 20 47 58 69 80 1 12 23 34 45 57 68 79 9 11 22 33 44 46 67 78 8 10 21 32 43 54 56 77 7 18 20 31 42 53 55 66 6 17 19 30 41 52 63 65 76 16 27 29 40 51 62 64 75 5 26 28 39 50 61 72 74 4 15 36 38 49 60 71 73 3 14 25 37 48 59 70 81 2 13 24 35