VB输出金字塔杨辉三角,帮忙改一下
Dimi()AsIntegerDimnAsIntegerDimaAsInteger,bAsIntegerPrivateSubCommand1_Click()n=Input...
Dim i() As Integer
Dim n As Integer
Dim a As Integer, b As Integer
Private Sub Command1_Click()
n = InputBox("输入")
ReDim i(n + 1, n + 1)
For a = 1 To n + 1
i(a, a) = 1: i(a, 1) = 1
Next a
For a = 3 To n + 1
For b = 2 To n
i(a, b) = i(a - 1, b - 1) + i(a - 1, b)
Next b
Next a
For a = 1 To n + 1
For b = 1 To a
Print Space(2 * (n - a + 1)); i(a, b);
If i(a, b) < 10 Then
Print Space(a);
Else
Print Space(a - 1);
End If
Next b
Print
Next a
End Sub
让他更贴近金字塔形状 展开
Dim n As Integer
Dim a As Integer, b As Integer
Private Sub Command1_Click()
n = InputBox("输入")
ReDim i(n + 1, n + 1)
For a = 1 To n + 1
i(a, a) = 1: i(a, 1) = 1
Next a
For a = 3 To n + 1
For b = 2 To n
i(a, b) = i(a - 1, b - 1) + i(a - 1, b)
Next b
Next a
For a = 1 To n + 1
For b = 1 To a
Print Space(2 * (n - a + 1)); i(a, b);
If i(a, b) < 10 Then
Print Space(a);
Else
Print Space(a - 1);
End If
Next b
Next a
End Sub
让他更贴近金字塔形状 展开
展开全部
Dim i() As Integer
Dim n As Integer
Dim a As Integer, b As Integer
Private Sub Command1_Click()
Dim sp1%
sp1 = 2 '因n而变
n = InputBox("输入")
ReDim i(n + 1, n + 1)
For a = 1 To n + 1
i(a, a) = 1: i(a, 1) = 1
Next a
For a = 3 To n + 1
For b = 2 To n
i(a, b) = i(a - 1, b - 1) + i(a - 1, b)
Next b
Next a
For a = 1 To n + 1
Print Space(sp1 * (n - a + 1) + 2);
For b = 1 To a
Print i(a, b) & Space(2 * sp1 - Len(i(a, b) & ""));
Next b
Print
Next a
End Sub
Dim n As Integer
Dim a As Integer, b As Integer
Private Sub Command1_Click()
Dim sp1%
sp1 = 2 '因n而变
n = InputBox("输入")
ReDim i(n + 1, n + 1)
For a = 1 To n + 1
i(a, a) = 1: i(a, 1) = 1
Next a
For a = 3 To n + 1
For b = 2 To n
i(a, b) = i(a - 1, b - 1) + i(a - 1, b)
Next b
Next a
For a = 1 To n + 1
Print Space(sp1 * (n - a + 1) + 2);
For b = 1 To a
Print i(a, b) & Space(2 * sp1 - Len(i(a, b) & ""));
Next b
Next a
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim i() As Integer
Dim n As Integer
Dim a As Integer, b As Integer
Private Sub Command1_Click()
n = InputBox("输入")
ReDim i(n + 1, n + 1)
For a = 1 To n + 1
i(a, a) = 1: i(a, 1) = 1
Next a
For a = 3 To n + 1
For b = 2 To n
i(a, b) = i(a - 1, b - 1) + i(a - 1, b)
Next b
Next a
For a = 1 To n + 1
Print Space(2 * (n - a + 1));
For b = 1 To a
Print i(a, b);
If i(a, b) < 10 Then
Print " ";
Else
Print "";
End If
Next b
Print
Next a
End Sub
Dim n As Integer
Dim a As Integer, b As Integer
Private Sub Command1_Click()
n = InputBox("输入")
ReDim i(n + 1, n + 1)
For a = 1 To n + 1
i(a, a) = 1: i(a, 1) = 1
Next a
For a = 3 To n + 1
For b = 2 To n
i(a, b) = i(a - 1, b - 1) + i(a - 1, b)
Next b
Next a
For a = 1 To n + 1
Print Space(2 * (n - a + 1));
For b = 1 To a
Print i(a, b);
If i(a, b) < 10 Then
Print " ";
Else
Print "";
End If
Next b
Next a
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询