Home > Back-end >  [problem description] enter a natural number N
[problem description] enter a natural number N

Time:09-25

[problem description]
Enter a natural number N (N 2 to 15), that output the following magic square, the side length of N * N, the element values are 1 to N * N, 1 in the upper left corner, each element is placed in turn clockwise,
When N=3:
1 2 3
8 and 9 4
7 June 5
[form] input
Read from standard input an integer N,
[] output form
To the standard output, printing as a result, the output meets the requirements of phalanx, every number of five character width and aligned to the right, at the end of each line are output a carriage return,
[input sample]
4
[output sample]
1 2 3 4
12 13 14 5
11 15 June 16
10 9 8 7
#include
# define Max 15
Void cube (int n, int a [Max] [Max])
{
int i;
for(i=0; i{
Int x=I, y=I, k=1;
While (yWhile (xWhile (y> I) a [x] [-] y=k++;
While (x> I) a [x -] [y]=k++;
}
If (n % 2!=0)
A [n/2) [n/2]=n * n;
}
Int main ()
{
int N;
The scanf (" % d ", & amp; N);
Int a [Max] [Max];
Cube (N, a);
for(int i=0; i{
for(int j=0; jPrintf (" % 5 d, "a [I] [j]);
}
printf("\n");
}
return 0;
}
For bosses to help find where is wrong?

CodePudding user response:

K=1, you have to put the for loop outside?
  • Related