Two-dimensional arrays in Pascal language: Matrix problems

Source: Internet
Author: User

"title" Square Fill number: In a n*n square, fill in ... The number of n*n, and requires the following form:

Fig. 10 11 12 1 9 16 13 2 8 15 14 3 7 6 5 4 "Get Started" observe the legend, it is not difficult to see this is a spiral matrix, the following is a large version of the color gradient, pure hand-made (with Wood has 2048 bright): "Core Code"
1//variable Assignment initial value2x:=0;//Horizontal Axis3y:=0;//Ordinate4i:=0;//number to fill in5k:=n;//the number of squares to fill each round6j:=1;//The direction of the number of fills,1From top to bottom ↓ or left to right →,-1when the opposite7//start to fill the number8  whileI<n*n Do9 beginTen  fori:=i+1  toI+k Do//Vertical ↑↓ Fill number Onex:x+J; Aa[x,y]:=i; - End;//End forLoops -Dec (k);//IE k:=k-1, the number of squares to be filled in the next line after each completion of a vertical line of fill-1 the ifj=1  ThenJ:=-1Elsej:=1;//control direction, this time from top to bottom or from left to right next time from bottom to top or right to left -  fori:=i+1  toI+k Do//horizontal → fill number - begin -y:=y+J; +a[x,y]:=i; - End; + End;//End whileCycle

Two-dimensional arrays in Pascal language: Matrix problems

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.