#Z01316. Magic Square
Magic Square
题目描述
Design a program to print the "magic square". A "magic square" is a square where the sum of each row, column and diagonal is equal.Such as:
首先将1写在第一行的中间。 之后,按如下方式从小到大依次填写每个数 K(K=2,3,⋯,N×N) : 若 (K-1) 在第一行但不在最后一列,则将 K 填在最后一行, (K-1) 所在列的右一列; 若 (K-1) 在最后一列但不在第一行,则将 K 填在第一列, (K-1) 所在行的上一行; 若 (K-1) 在第一行最后一列,则将 K 填在 (K-1) 的正下方; 若 (K-1) 既不在第一行,也不在最后一列,如果 (K-1) 的右上方还未填数,则将 K 填(K-1) 的右上方,否则将K填在 (K-1) 的正下方。
输入格式
The input file has only one line and contains an integer N that is odd, the size of the magic square. 1<N<39.
输出格式
Output file contains N rows, each row N integers, namely according to the above method to construct N ∗ N magic square. Two adjacent integers are separated by a single space. different N*N magic with a blank line
3
8 1 6
3 5 7
4 9 2
豫公网安备41072702000346号