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 展开
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 展开
展开全部
修改成如下一段代码,可以输出很清晰的杨辉三角形,而且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
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
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询