VB用print窗体显示杨辉三角

请问谁会用VB编写一个单击一下按钮就可以在窗体上显示出杨辉三角,最好是金字塔形的,可以的话,在代码旁写上解释文字会比较好,这样我会容易点明白,谢谢!... 请问谁会用VB编写一个单击一下按钮就可以在窗体上显示出杨辉三角,最好是金字塔形的,可以的话,在代码旁写上解释文字会比较好,这样我会容易点明白,谢谢! 展开
 我来答
匿名用户
2014-01-04
展开全部
Private Sub Form_Click()
Dim A() As Long, N As Long, I As Long, J As Long, X As Long
N = Val(InputBox("请输入打印行宴带数<=16", "输入正整陪祥型数", 16))
If N > 16 Or N <= 0 Then
MsgBox "数值错误芦猜,重新输入行数"
N = 0
End If
ReDim A(N, N)
Me.Cls
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 Spc(75 - 3 * I);
For J = 1 To I
Print A(I, J);
X = Len(CStr(A(I, J)))
If X = 1 Then Print Spc(3);
If X = 2 Then Print Spc(2);
If X = 3 Then Print Spc(1);
Next J
Print
Print
Next I
End Sub
匿名用户
2014-01-04
展开全部
Private Sub Form_Click()
Dim i As Integer, j As Integer, m As Integer
m = InputBox("请输键者入数斗亮培组的行空唯、列数")
ReDim a(m, m) As Integer
Call P(a, m)
For i = 1 To m
For j = 1 To i
Print Tab(j * 3); a(i, j);
Next j
Print
Next i

End Sub

Private Sub P(b() As Integer, n As Integer)
Dim i As Integer, j As Integer
For i = 1 To n
b(i, 1) = 1: b(i, i) = 1
Next i
For i = 3 To n
For j = 2 To i - 1
b(i, j) = b(i - 1, j - 1) + b(i - 1, j)
Next j, i
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式