VB数组操作

来源:百度知道 编辑:UC知道 时间:2024/09/22 12:44:38
使用动态二维数组存储杨辉三角形的前n行,n由键盘输入。在图片框中输出结果。
提示:杨辉三角形数据规律为:
yh(i,1) = 1,yh(i,i) = 1 (1≤i≤n)
yh(i,j) = yh(i – 1,j - 1) + yh(i - 1,j) (2≤i≤n, 2≤j<i)
谢谢帮忙啊,要交作业的,又不会

Dim yh() As Long

Private Sub Command1_Click()
Dim str1 As String, i As Integer, j As Integer, N As Integer
redo:
str1 = InputBox("请输入正整数N:", "输入", 10)
If Not IsNumeric(str1) Then GoTo redo
N = Val(str1)
ReDim yh(N, N)
yh(1, 1) = 1
Print yh(1, 1)
For i = 2 To N
For j = 1 To i
yh(i, j) = yh(i - 1, j - 1) + yh(i - 1, j)
Print yh(i, j);
Next j
Print
Next i
End Sub

1111111

杨辉三角百度知道里很多的。。你有时间可以找找看看。。
你写的这个数据规律看不明白。。最好是举个例子容易懂些。。

Dim n As Integer, i, j
n = InputBox("请输入杨辉三角形的行数", "输入", 6)
ReDim yh(n, n) As Integer
For i = 1 To n

For j = 1 To i
If j = 1 Or j = i Then
yh(i, j) = 1
Else
yh(i, j) = yh(i - 1, j - 1) + yh(i - 1, j)
End If
Next
Next
Picture1.Cls
For i = 1 To n
Picture1.Pr