用vb.net2008打印杨辉三角形(打印10行),要求如图所示

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/17 14:40:17
用vb.net2008打印杨辉三角形(打印10行),要求如图所示用vb.net2008打印杨辉三角形(打印10行),要求如图所示用vb.net2008打印杨辉三角形(打印10行),要求如图所示Publ

用vb.net2008打印杨辉三角形(打印10行),要求如图所示
用vb.net2008打印杨辉三角形(打印10行),要求如图所示


用vb.net2008打印杨辉三角形(打印10行),要求如图所示
Public Class Form1

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim n As Integer, i As Integer, j As Integer, a(,) As Integer
n = 10
ReDim a(n + 1, n + 1)
For i = 1 To n + 1
a(i, 1) = 1 : a(i, i) = 1 : Next i
For i = 3 To n + 1
For j = 2 To i - 1
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
Next j, i
For i = 1 To n + 1
For j = 1 To i
TextBox1.AppendText(Space(4 - Len(Trim(Str(a(i, j))))) & Trim(Str(a(i, j))))
Next j
TextBox1.AppendText(vbCrLf)
Next i
End Sub
End Class