等腰的杨辉三角VB代码

PrivateSubForm_Click()DimA()AsLong,NAsInteger,IAsInteger,JAsIntegerN=Val(InputBox("指定... Private Sub Form_Click()
Dim A() As Long, N As Integer, I As Integer, J As Integer
N = Val(InputBox("指定行数"))
ReDim A(N, N)
For I = 1 To N
For J = 1 To I
If J = 1 Or I = J Then
A(I, J) = 1
Else
A(I, J) = A(I - 1, J - 1) + A(I - 1, J)
End If
Next J
Next I
For I = 1 To N
Print Tab(2 * (N + 2) - 2 * (I + 2) + 3);
For J = 1 To I
Print A(I, J);
Next J
Print
Next I
End Sub
大神帮忙改改 这个打出来的三角形是歪的,在打印的时候判断位数,位数多的就多加空格,这个地方怎么改啊,我总是改成下标越界
展开
 我来答
syx54
2015-04-14 · TA获得超过7378个赞
知道大有可为答主
回答量:6567
采纳率:83%
帮助的人:2744万
展开全部
这样满意不?
Dim A() As Long, N As Integer, I As Integer, J As Integer
N = Val(InputBox("指定行数"))
ReDim A(N, N)
For I = 1 To N
For J = 1 To I
If J = 1 Or I = J Then
A(I, J) = 1
Else
A(I, J) = A(I - 1, J - 1) + A(I - 1, J)
End If
Next J
Next I
For I = 1 To N
Print Tab(2 * (N + 2) - 2 * (I + 2) + 3);
For J = 1 To I
Print Right(" " & CStr(A(I, J)), 2); " ";
Next J
Print
Next I
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式