vb打印出杨辉三角的代码怎么写
1个回答
展开全部
窗体上添加一个按钮,代码如下:
Option Explicit
Private Sub Command1_Click()
Dim N As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
N = InputBox("请输入行数!", , 10)
ReDim a(N + 1, N + 1), b(N + 1, N + 1)
Cls
k = 8
For i = 1 To N
Print String((N - i) * k / 2 + 1, " ");
For j = 1 To i
a(i, 1) = 1
a(i, i) = 1
a(i + 1, j + 1) = a(i, j) + a(i, j + 1)
b(i, j) = Trim(Str(a(i, j)))
Print b(i, j); String(k - Len(b(i, j)), " ");
Next j
Print
Next i
End Sub
Option Explicit
Private Sub Command1_Click()
Dim N As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
N = InputBox("请输入行数!", , 10)
ReDim a(N + 1, N + 1), b(N + 1, N + 1)
Cls
k = 8
For i = 1 To N
Print String((N - i) * k / 2 + 1, " ");
For j = 1 To i
a(i, 1) = 1
a(i, i) = 1
a(i + 1, j + 1) = a(i, j) + a(i, j + 1)
b(i, j) = Trim(Str(a(i, j)))
Print b(i, j); String(k - Len(b(i, j)), " ");
Next j
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询