用vb编写杨辉三角的程序代码,有没有哪位能指点一下,谢谢。

由于我刚学vb,请尽量写的完整些。。... 由于我刚学vb,请尽量写的完整些。。 展开
 我来答
liuyuwxj
推荐于2016-12-06 · TA获得超过2.6万个赞
知道大有可为答主
回答量:1777
采纳率:100%
帮助的人:1526万
展开全部

Private Sub Command1_Click()

  n = Val(Text1.Text)

    ReDim a(n + 1, n + 1), b(n + 1, n + 1)

    Cls

    k = 8

    For i = 1 To n

    Print String((n - i) * k / 2 + 1, " ");

    For j = 1 To i

    a(i, 1) = 1

    a(i, i) = 1

    a(i + 1, j + 1) = a(i, j) + a(i, j + 1)

    b(i, j) = Trim(Str(a(i, j)))

    Print b(i, j); String(k - Len(b(i, j)), " ");

    Next j

    Print

    Next i

End Sub

创建一个text和command,在text中输入所需行数,点击command即可

本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
葛檬
2010-06-22 · TA获得超过189个赞
知道小有建树答主
回答量:139
采纳率:0%
帮助的人:189万
展开全部
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ch As Char
Dim b As Boolean = True
If (TextBox1.Text = "") Or (Val(TextBox1.Text) = 0) Then GoTo 1
For Each ch In TextBox1.Text
If (Asc(ch) > 57) Or (Asc(ch) < 48) Then
b = False
Exit For
End If
Next
If b = False Then
1: MsgBox("请输入正确的计算序列数!")
TextBox1.Clear()
TextBox1.Focus()
Exit Sub
End If
Label3.Text = "运行计算"
RichTextBox1.Clear()
Timer1.enabled = True

End Sub
Private Sub CountNumber(ByVal Value As Integer)
ProgressBar1.Value = 0
Dim Array()() As Long = New Long(Value - 1)() {}
Dim a, b, l As Integer
Dim s1, s2 As Double
s2 = 0
s1 = 100 / Value
For a = 0 To (Value - 1)
Array(a) = New Long(a + 1) {}
Next
For a = 0 To (Value - 1)
For b = 0 To (a + 1)
Array(a)(b) = 0
Next
Next
Array(0)(0) = 1
For a = 1 To (Value - 1)
For b = 0 To (a)
If b = 0 Then Array(a)(b) = 1 Else Array(a)(b) = Array(a - 1)(b) + Array(a - 1)(b - 1)
Next
Next
l = Len(Str(Array(Value - 1)(Math.Truncate(Value / 2) + 1))) - 1
If CheckBox1.Checked = True Then
RichTextBox1.Text = St(Len(Str(Array.Length + 1)) - 1, "", 1)
For a = 1 To (Array(Val(Value - 1)).Length - 1)
RichTextBox1.Text = RichTextBox1.Text & St(l + 2, Val(a), 1)
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13) & Chr(13)
End If
If CheckBox1.Checked = True Then
For a = 0 To (Value - 1)
RichTextBox1.Text = RichTextBox1.Text & St(Len(Array.Length + 1) - Len(Str(a)), Val(a), 2)
For b = 0 To a
RichTextBox1.Text = RichTextBox1.Text & St(l + 2, Val(Array(a)(b)), 1)
Next
s2 = s2 + s1
ProgressBar1.Value = Math.Truncate(s2)
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
Next
Else
For a = 0 To (Value - 1)
For b = 0 To (a)
RichTextBox1.Text = RichTextBox1.Text & St(l, Val(Array(a)(b)), 1)
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
s2 = s2 + s1
ProgressBar1.Value = Math.Truncate(s2)
Next
End If
Label3.Text = "等待命令"
End Sub
Private Function St(ByVal Value As Integer, ByVal s As String, ByVal l As Integer)
Dim a As Integer
St = s
If l = 2 Then
For a = 1 To (Value - Len(s))
St = St & " "
Next
Exit Function
End If
For a = 1 To (Value - Len(s))
St = " " & St
Next
End Function

Private Sub Timer1_Timer()
CountNumber(Val(TextBox1.Text))
Timer1.Enabled = False
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式