Public Class 例5_13

    Private Sub 例5_13_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a(,) As Integer, n As Integer
        Dim i As Integer, j As Integer, p As String = ""
        n = InputBox("请输入杨辉三角形的行数")
        ReDim a(n - 1, n - 1)     '根据实际需求，重新定义数组
        For i = 0 To n - 1
            For j = 0 To i
                If j = 0 Or i = j Then
                    a(i, j) = 1
                Else
                    a(i, j) = a(i - 1, j) + a(i - 1, j - 1)
                End If
                p = p & a(i, j) & vbTab
            Next
            p = p & vbCrLf
        Next
        MsgBox(p, vbOKOnly, "杨辉三角形")
    End Sub
End Class