Some training questions for C and C + + (10) (Print spiral Phalanx)

Source: Internet
Author: User

Issue: To write a spiral phalanx. The spiral phalanx form is as follows:

1 12 11 10

2 13 16 9

3 14 15 8

4 5 6 7

Set Row,column to represent row, column coordinates, the variable p from 1 to N2 p in order to the array A[row][column], to determine the row, colomn changes. The analysis is as follows: Introduce the variable k, the initial value is N. When the data is deposited to the lower-left or upper-right corner, K minus 1, which guarantees the output matrix. The introduction of the variable T, the initial value of 1, when the data is deposited to the lower right corner, the T changes in accordance with, when deposited in the upper left corner, T and change in accordance with, so that the assignment to the correct array coordinates.

Some training questions for C and C + + (10) (Print spiral Phalanx)

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: 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.