天津奢侈品包包护理:用vb帮我编写杨辉三角形六行的程序

来源:百度文库 编辑:神马品牌网 时间:2024/05/12 12:33:47
要代码 1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
用VB.NET或ASP.NET

下面有杨辉三角20行的代码,你可修改后用:
Option Explicit
Dim a(21, 21) As Long
Dim b(21) As String
Dim i As Byte
Dim j As Byte

Private Sub Form_Load()
a(0, 0) = 1
For i = 1 To 20
For j = 1 To 20
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
If a(i, j) <> 0 Then
b(j) = b(j - 1) & " " & a(i, j)
End If
Next
Print b(i)
Next
End Sub

先把form的autoredraw属性改成true,代码如下:
==========================
Option Explicit

Dim a(7, 7) As Long
Dim b(7) As String
Dim i As Byte
Dim j As Byte

Private Sub Form_Load()
a(0, 0) = 1
For i = 1 To 6
For j = 1 To 6
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
If a(i, j) <> 0 Then
b(j) = b(j - 1) & " " & a(i, j)
End If
Next
Print b(i)
Next
End Sub