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

让他更贴近金字塔形状
展开
 我来答
ynzsvtzhidao
2011-03-27 · TA获得超过248个赞
知道小有建树答主
回答量:243
采纳率:0%
帮助的人:314万
展开全部
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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
Ynzsvt
2011-03-27 · TA获得超过6664个赞
知道大有可为答主
回答量:1.5万
采纳率:40%
帮助的人:2682万
展开全部
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
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式