用vb.net2008打印杨辉三角形(打印10行),要求如图所示
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/24 17:28:21
用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