1347 N-level cube

Source: Internet
Author: User
Description

The so-called "N-level cube" is a number filling game ~ N ^ 2 numbers are repeatedly filled in a square matrix consisting of n rows and n columns, N ^ 2 squares, the sum of numbers in each row, column, and diagonal line in the square matrix is equal to the same number, and N is an odd number.

(Follow the 89 pages of the teaching material strictly.AlgorithmOperation. If the write is not performed as required, the non-AC status will occur and the consequences will be borne by you)

Input

The first behavior t indicates that T groups of data exist.

Each of the following lines contains an integer n (n <= 10)

Output

Corresponding to the Cube filled in for each N output, each number has a space, each n numbers a row

 

 

 

 

Find the rule and print it cyclically.

# Include <stdio. h> main () {int A [99] [99]; int N, I, j, R; int number, Te; scanf ("% d", & number ); for (TE = 1; te <= number; Te ++) {scanf ("% d", & N); for (I = 0; I <99; I ++) {for (j = 0; j <99; j ++) {A [I] [J] = 0 ;}} I = 0; j = n/2; A [I] [J] = 1; for (r = 2; r <= N * n; r ++) if (A [(I + N-1) % N] [(j + 1) % N] = 0) {I = (I + N-1) % N; j = (J + 1) % N; A [I] [J] = r;} else {I = (I + 1) % N; A [I] [J] = r ;}for (I = 0; I <n; I ++) {for (j = n-1; j> = 0; j --) {printf ("% d", a [I] [J]);} printf ("\ n ");}}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.