1 /// <summary>2 ///Nine Gongge algorithm3 /// </summary>4 Public voidninetable ()5 {6 //Create a third-order phalanx7 int[,] arr =New int[3,3];8 //row subscript for line 3rd9 intA =2;Ten //row subscript for line 2nd One intb =3/2; A //Assigning a value to an array - for(inti =1; I <=9; i++) - { thearr[a++, b++] =i; - - //If I is a multiple of 3 - ifI3==0) + { -A = A-2; +B = B-1; A } at Else //If I is not a multiple of 3 - { -A = a%3; -b = b%3; - } - } in -StringBuilder SB =NewStringBuilder (); to //traversing output nine lattice + for(inti =0; I <3; i++) - { the for(intj =0; J <3; J + +) * { $Sb. Append (Arr[i, J]. ToString () +" ");Panax Notoginseng } -Sb. Append ("<br/>"); the } +Lbninetable.text ="output nine lattice:<br/>"+sb. ToString (). Trim (); A}
View Code
The results of the program run are as follows:
Output Nine Gongge:
4 9 2
3 5 7
8 1 6
1 to 9 numbers are added to each row after the number is equal to the nine Gongge algorithm of 15