Cube array, also known as "Landscape Chart" in ancient times, refers to the composition elements of natural numbers 1, 2... N's Level

Source: Internet
Author: User
For example, 3 × 3 cube Arrays: 816357492 cube arrays are arranged as follows: (1) Place 1 in the middle column of the first row; (2) the numbers starting from 2 until n × n are stored in sequence according to the following rules. The number of rows in each number is 1 less than the number of rows in the previous number, and the number of columns is 1 (for example, the third-level cube array above, 5); (3) if the number of rows in the previous row is 1

For example, the arrangement of the 3x3 cube array: 816 357 cube array is as follows: (1) Place 1 in the middle column of the first row; (2) the numbers starting from 2 until n × n are stored in sequence according to the following rules. The number of rows in each number is 1 less than the number of rows in the previous number, and the number of columns is 1 (for example, the third-level cube array above, 5); (3) if the number of rows in the previous row is 1

For example, a 3 × 3 cube array:
8 1 6
3 5 7
4 9 2
The arrangement rules of cube arrays are as follows:
(1) Place 1 in the middle column of the first row;
(2) The numbers starting from 2 until n × n are stored in sequence according to the following rules. The number of rows in each number is 1 less than the number of rows in the previous number, add 1 to the number of columns (for example, the third-level cube array above, and 5 to the last row and the last column of 4 );
(3) If the number of rows in the previous row is 1, the number of rows in the next row is n (the bottom row). For example, if 1 is in the first row, 2 should be placed in the bottom row, add 1 to the number of columns;
(4) when the number of columns in the previous row is n, the number of columns in the next row is 1, and the number of rows minus 1. For example, if 2 is in the last column of row 3rd, 3 should be placed in the first column of the Second row;

(5) If there is an existing number at the position specified by the preceding rule, or the previous number is the nth column of the first row, the next number is placed below the previous number. For example, according to the above rules, 4 should be placed in the 1st columns of the 2nd rows, but this position has been occupied, SO 4 should be placed below 3;

# Include
Int main ()
{
Int a [15] [15], I, j, k, p, n;
P = 1;
While (p = 1)
{
Printf ("enter n (n = 1--15 ):");
Scanf ("% d", & n );
If (n! = 0) & (n <= 15) & (n % 2! = 0 ))
P = 0;
}
For (I = 1; I <= n; I ++)
For (j = 1; j <= n; j ++)
A [I] [j] = 0;
J = n/2 + 1;
A [1] [j] = 1;
For (k = 2; k <= n * n; k ++)
{
I = I-1;
J = j + 1;
If (I <1 & j> n)
{
I = I + 2;
J = J-1;
}
Else
{
If (I <1) I = n;
If (j> n) j = 1;
}
If (a [I] [j] = 0)
A [I] [j] = k;
Else
{
I = I + 2;
J = J-1;
A [I] [j] = k;
}
}
For (I = 1; I <= n; I ++)
{
For (j = 1; j <= n; j ++)
Printf ("% 5d", a [I] [j]);
Puts ("");
}
Return 0;
}

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.