N行的杨辉三角形 VB

请帮我改一下,这个程序只能显示10行的杨辉三角形,怎样把它改成n行PrivateSubCommand1_Click()Dimrstr(10)AsStringDima(10... 请帮我改一下,这个程序只能显示10行的杨辉三角形,怎样把它改成n行
Private Sub Command1_Click()
Dim rstr(10) As String
Dim a(10, 10) As Integer
Dim newstrr As String
Dim strr As String
Dim z%

z = Val(Text1.Text)
Picture1.Cls

Randomize

For i = 0 To 10
a(i, 0) = 1
Next i

For i = 1 To 10
newstrr = ""
For j = 1 To i
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
strr = Str(a(i, j))
newstrr = newstrr & strr
rstr(i) = newstrr
Next j
Next i
rstr(0) = "1"
rstr(1) = "1" & " 1"

For n = 2 To 10
rstr(n) = "1" & rstr(n)
Next

For m = 0 To (z - 1)
Picture1.Print rstr(m)
Next
Text1.Text = ""
Text1.SetFocus
End Sub
展开
 我来答
玫瑰为你盛开
2009-05-19
知道答主
回答量:0
采纳率:0%
帮助的人:0
展开全部
修改成如下一段代码,可以输出很清晰的杨辉三角形,而且N最大可以取到54(以上的可能都取不到40):

Private Sub Command1_Click()
Dim rstr() As String
Dim a() As Double
Dim newstrr As String
Dim strr As String
Dim z%

z = Int(Val(Text1.Text))
'防错处理
If z = 0 Then MsgBox "请在输入框内输入大于0小于55的行数!": Exit Sub
If z > 54 Then MsgBox "请在输入框内输入大于0小于55的行数!": Exit Sub
Picture1.Cls
Picture1.AutoRedraw = True
ReDim rstr(z) As String '最好用redim
ReDim a(z, z) As Double
Randomize

For i = 0 To z
a(i, 0) = 1
Next i

For i = 1 To z
For j = 1 To i
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
Next j
Next i

For i = 1 To z
newstrr = ""
For j = 1 To i
strr = Str(a(i, j)) & Space(Len(Str(a(z, j))) - Len(Str(a(i, j))))
newstrr = newstrr & strr
rstr(i) = newstrr
Next j
Next i

rstr(0) = "1"
rstr(1) = "1" & " 1"

For n = 2 To z
rstr(n) = "1" & rstr(n)
Next

For m = 0 To (z - 1)
Picture1.Print rstr(m)
Next
Text1.Text = ""
Text1.SetFocus
End Sub
zdingyun
2009-05-19
知道答主
回答量:0
采纳率:0%
帮助的人:0
展开全部
Option Explicit
Dim a() As Long
Dim b() As String
Dim n As Integer
Dim i As Byte
Dim j As Byte

Private Sub Command1_Click()
Cls
n = InputBox("N=", n)
ReDim a(n, n)
ReDim b(n)
a(0, 0) = 1
For i = 1 To n - 1
For j = 1 To n - 1
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
If a(i, j) <> 0 Then
b(j) = b(j - 1) & " " & a(i, j)
End If
Next
Print b(i)
Next
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
lxz1969
2009-05-19
知道答主
回答量:0
采纳率:0%
帮助的人:0
展开全部
Private Sub Command1_Click()
Dim rstr() As String
Dim a() As Integer
Dim newstrr As String
Dim strr As String
Dim z%

z = Val(Text1.Text)
Picture1.Cls
Dim rstr(z) As String
Dim a(z,z) As Integer
Randomize

For i = 0 To z
a(i, 0) = 1
Next i

For i = 1 To z
newstrr = ""
For j = 1 To i
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
strr = Str(a(i, j))
newstrr = newstrr & strr
rstr(i) = newstrr
Next j
Next i
rstr(0) = "1"
rstr(1) = "1" & " 1"

For n = 2 To z
rstr(n) = "1" & rstr(n)
Next

For m = 0 To (z - 1)
Picture1.Print rstr(m)
Next
Text1.Text = ""
Text1.SetFocus
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式