编一个VB程序,输出一个杨辉三角形
也就是说用有关数组的知识编写如下图形:111121133114641151010511615201561172135352171182856705628811936841...
也就是说用有关数组的知识编写如下图形:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
老弟,你说的Debug.是什么意思?我是个VB新手哎,太难懂了 展开
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
老弟,你说的Debug.是什么意思?我是个VB新手哎,太难懂了 展开
3个回答
展开全部
Private Sub Form_Click()
Const N = 10
Dim a(N, N) As Integer
Dim i, j As Integer
a(0, 0) = 1
a(1, 0) = 1
a(1, 1) = 1
For i = 2 To N - 1
a(i, 0) = 1
a(i, i) = 1
For j = 1 To i - 1
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
Next j, i
For i = 0 To N - 1
For j = 0 To i
Print a(i, j);
Next j
Print
Next i
End Sub
Const N = 10
Dim a(N, N) As Integer
Dim i, j As Integer
a(0, 0) = 1
a(1, 0) = 1
a(1, 1) = 1
For i = 2 To N - 1
a(i, 0) = 1
a(i, i) = 1
For j = 1 To i - 1
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
Next j, i
For i = 0 To N - 1
For j = 0 To i
Print a(i, j);
Next j
Next i
End Sub
展开全部
下列代码是用VB6.0实现的,运行后在调试窗口输出
Dim n(1 To 20) As Long, t As Long, i As Long
n(1) = 1
t = 0
Debug.Print 1
For i = 1 To UBound(n)
If i = 1 Then
t = 1
Else
n(i) = n(i) + t
t = n(i) - t
End If
If n(i) = 0 Then
i = 0
Debug.Print
Else
Debug.Print n(i),
End If
Next
Dim n(1 To 20) As Long, t As Long, i As Long
n(1) = 1
t = 0
Debug.Print 1
For i = 1 To UBound(n)
If i = 1 Then
t = 1
Else
n(i) = n(i) + t
t = n(i) - t
End If
If n(i) = 0 Then
i = 0
Debug.Print
Else
Debug.Print n(i),
End If
Next
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1
1 2 1
1 3 3 1
????????
1 2 1
1 3 3 1
????????
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询