After the numbers from 1 to 9 are filled, the numbers in each column in each row are added to the 15-square-lattice algorithm.

Source: Internet
Author: User

After the numbers from 1 to 9 are filled, the numbers in each column in each row are added to the 15-square-lattice algorithm.
1 /// <summary> 2 /// nine cells algorithm 3 /// </summary> 4 public void NineTable () 5 {6 // create a Third-Order Matrix 7 int [,] arr = new int [3, 3]; 8 // row subscript 9 int a = 2; 10 // row subscript of 2nd rows 11 int B = 3/2; 12 // assign 13 for the Array (int I = 1; I <= 9; I ++) 14 {15 arr [a ++, B ++] = I; 16 17 // if I is a multiple of 3 18 if (I % 3 = 0) 19 {20 a = a-2; 21 B = B-1; 22} 23 else // If I is not a multiple of 3 24 {25 a = a % 3; 26 B = B % 3; 27} 28} 29 30 StringBuilder sb = new StringBuilder (); 31 // traverse the output of the 9-Cell 32 for (int I = 0; I <3; I ++) 33 {34 for (int j = 0; j <3; j ++) 35 {36 sb. append (arr [I, j]. toString () + ""); 37} 38 sb. append ("<br/>"); 39} 40 lbNineTable. text = "output nine cells: <br/>" + sb. toString (). trim (); 41} View Code

 

The running result is as follows:

Output:
4 9 2
3 5 7
8 1 6

Related Article

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.