Print Pascal's Triangle problem-solving ideas

topic:

Problem-solving difficulties exist:

1. Pascal's Triangle is difficult to link with two-dimensional arrays.

2. discover the laws of each number appears it is hard to fashion c language to write code.

solution:

Finishing examples of Pascal's Triangle to make it resemble a two-dimensional array; carefully to find the law of each number appears, finishing as systematic expression.

Specific problem-solving steps:

Finishing examples of Pascal's Triangle in the form of two-dimensional array, not digital position instead of 0. As shown below:

Thus, the law of each number appeared arise: in addition to the first "1", each number is equal to row with him on a line with the number of x1 x1 a number of former and. I.e., a [i] [j] = a [i-1] [j] + a [i-1] [j-1]. The number of rows and the number of spaces before the first two-dimensional array equal to the number minus one, the number of spaces, each line minus one.

A digital data before the first space is equal to the number of rows minus one, the number of spaces after the beginning of each line time minus one. After sorting out the law, only the code into a form to which it is easy for us to code Agriculture (> - <)

flow chart:

The main code:

Guess you like

Origin www.cnblogs.com/shxnb/p/12051855.html