我有一段vb程序,想要输出杨辉三角任意指定的行数,不知道哪儿有毛病了,老是说要求常数表达式,帮帮我
拜托了程序代码:PrivateSubForm_Click()DimnAsIntegerDimiAsInteger,jAsInteger,a(n,n)AsIntegerFo...
拜托了
程序代码:
Private Sub Form_Click()
Dim n As Integer
Dim i As Integer, j As Integer, a(n, n) As Integer
For i = 1 To n
n = Val(InputBox("请输入行数:"))
a(i, 1) = 1
a(i, i) = 1
Next i
For j = 2 To i - 1
a(i, j) = a(i - 1, j) + a(i - 1, j - 1)
Next j
For i = 1 To n
For j = 1 To i
Print a(i, j)
Next j
Next i
End Sub 展开
程序代码:
Private Sub Form_Click()
Dim n As Integer
Dim i As Integer, j As Integer, a(n, n) As Integer
For i = 1 To n
n = Val(InputBox("请输入行数:"))
a(i, 1) = 1
a(i, i) = 1
Next i
For j = 2 To i - 1
a(i, j) = a(i - 1, j) + a(i - 1, j - 1)
Next j
For i = 1 To n
For j = 1 To i
Print a(i, j)
Next j
Next i
End Sub 展开
1个回答
展开全部
Dim n As Integer
Dim i As Integer, j As Integer, a() As Integer
n = Val(InputBox("请输入行数:", , 6))
ReDim a(n, n) '重定义
For i = 1 To n
a(i, 1) = 1 : a(i, i) = 1
For j = 2 To i - 1
a(i, j) = a(i - 1, j) + a(i - 1, j - 1)
Next j
Next i
'---------输出-----------------
For i = 1 To n
For j = 1 To i
Print a(i, j);
Next j
Print
Next i
Dim i As Integer, j As Integer, a() As Integer
n = Val(InputBox("请输入行数:", , 6))
ReDim a(n, n) '重定义
For i = 1 To n
a(i, 1) = 1 : a(i, i) = 1
For j = 2 To i - 1
a(i, j) = a(i - 1, j) + a(i - 1, j - 1)
Next j
Next i
'---------输出-----------------
For i = 1 To n
For j = 1 To i
Print a(i, j);
Next j
Next i
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询