输入整数N,现实具有N行的杨辉三角形,要求按正三角形的形式在图片框中显示注意是正三角形,在图片框中显示.
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/28 03:08:11
输入整数N,现实具有N行的杨辉三角形,要求按正三角形的形式在图片框中显示注意是正三角形,在图片框中显示.
输入整数N,现实具有N行的杨辉三角形,要求按正三角形的形式在图片框中显示
注意是正三角形,在图片框中显示.
输入整数N,现实具有N行的杨辉三角形,要求按正三角形的形式在图片框中显示注意是正三角形,在图片框中显示.
Option Explicit
Dim n As Integer, i As Integer, j As Integer, a() As Integer
Private Sub Command1_Click()
'判断输入的行数是否为数字
If IsNumeric(Text1.Text) Then
n = Val(Text1.Text)
Else
MsgBox "您输入的不是数字"
Text1.SetFocus
End If
'重新定义数组并利用两次循环给数组赋值
ReDim a(n, n) As Integer
For i = 1 To n
a(i, 1) = 1: a(i, i) = 1
Next i
For i = 3 To n
For j = 2 To i - 1
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
Next j
Next i
'输出数组到picturebox1上
For i = 1 To n
For j = 1 To i
Picture1.Print a(i, j); Spc(1);
Next j
Picture1.Print
Next i
End Sub
Private Sub Command2_Click()
'判断输入的行数是否为数字
If IsNumeric(Text1.Text) Then
n = Val(Text1.Text)
Else
MsgBox "您输入的不是数字"
Text1.SetFocus
End If
'重新定义数组并利用两次循环给数组赋值
ReDim a(n, n) As Integer
For i = 1 To n
a(i, 1) = 1: a(i, i) = 1
Next i
For i = 3 To n
For j = 2 To i - 1
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
Next j
Next i
'输出数组到picturebox2上
For i = 1 To n
Picture2.Print Spc((n - i) * 2);
For j = 1 To i
Picture2.Print a(i, j); Spc(1);
Next j
Picture2.Print
Next i
End Sub
Private Sub Command3_Click()
'清除屏幕
Picture1.Cls
Picture2.Cls
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub