matlab输出n阶杨辉三⾓,编写⼀个输出n阶杨辉三⾓形的函
数,⽤主函数–⼿机爱问...
2014-05-15
VB中,怎样把杨辉三⾓形显⽰在图⽚框中
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) ...全部
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数组全部赋值为1
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。收起

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。