Pascal triangle shape can be arranged as below:
1
121
1331
14641
15101051
................
To facilitate understanding of each element of the above can we put in the matrix as follows:
- Number 1 in row 1 column 1
- Number 1 in row 2 column 1, number 2 in row 2 column 2, number 1 row 2 column 3
- Number 1 in row 3 column 1, number 3 in row 3 column 2, number 3 in row 3 column 3, number 1 in row three column 4
and so on
We note that each line has a lot of counting elements such as the following:
First-line there is 1 element
The second-row there are 3 elements
The third-row there are 4 elements
Fourth-line there are 5 elements
-And so on
The second line, third, fourth and so on plus-plus element two.
Suppose there is a matrix A (N, M), then these values can be entered as follows:
A (1,1) = 1
A (2,1) = 1
A (2,2) = 2
A (2,3) = 1
A (3,1) = 1
A (3,2) = 3
A (3.3) = 3
A (3,4) = 1
and so on
To facilitate workmanship we will initialize 2 pieces of array elements
About the way the process as follows:
0. Start
1. Specify many levels, say N, Determine matrix A (10.10)
Define A (1,1) = 1, A (1,2) = 1
2. Print row and first column
3. Starting first from 2 to N
4. Print 1
5. Ranging from 2 to I
Determine the next value
Value = A (I-1, J-1) + A (I-1, J)
Value = matrix current line minus one, minus one column current + current reduced matrix row one, column today.
Print Values
6. Repeat to 5
7. Print 1
8. Down Line
9. Repeat to 3
10. completed
Private Sub Form_Activate ()
Dim A (10.10) As Byte
A (1,1) = 1 'Initialize
A (1,2) = 1 'Initialize
print A (1,1) 'print the first line
For I = 2 To 10 Step 1 'value 10 is considered a level up to 10
print "1"
For J = 2 To First Step 1
Value = A (I-1, J-1) + A (I-1, J)
print value;
Next J
Print "1";
Print 'Down Line
Next I
End Sub
Monday, June 6, 2011
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment