# VB基础入门教程最后一课，书籍推荐，配套程序和代码的发布-VB教程021

VB基础入门教程最后一课，书籍推荐，配套程序和代码的发布-VB教程021

bilibili：https://space.bilibili.com/54144454/#/channel/detail?cid=43133

1.乘法口诀表

Dim i, j As Integer

Dim s As String

Text1.Text = ""

For i = 1 To 9

For j = 1 To i

s = Str(i) + "X" + Str(j) + "=" + Str(i * j)

Text1.Text = Text1.Text + s

Next j

Text1.Text = Text1.Text + vbCrLf

Next i

2.枚举算法

List1.Clear

Dim x, y, c As Integer

For x = 0 To 240

For y = 0 To 100

If 5 * x + 12 * y = 1200 Then

List1.AddItem Str(x) + " " + Str(y)

c = c + 1

End If

Next y

Next x

Text1.Text = Str(c)

3.解析算法

Text2.Text = ""

Dim x, y As Double

x = Val(Text1.Text)

Do While x > 0

y = x Mod 2

x = x \ 2

Text2.Text = Str(y) + Text2.Text

Loop

4.冒泡排序

List2.Clear

n = 5

For i = 1 To n - 1

For j = n To i + 1 Step -1

If a(j)

t = a(j): a(j) = a(j - 1): a(j - 1) = t

End If

Next j

Next i

For y = 1 To 5

Next y

5.选择排序

List2.Clear

n = 5

For i = 1 To n - 1

k = i

For j = i + 1 To n

If a(k) > a(j) Then k = j

Next j

If k i Then

t = a(k): a(k) = a(i): a(i) = t

End If

Next i

For y = 1 To 5

Next y

6.顺序查找

Dim n, Key As Integer

Dim f As Boolean

f = False

n = 5

Key = Val(Text1.Text)

For i = 1 To n

If a(i) = Key Then

Label1.Caption = Str(a(i)) + "已找到"

f = True

Exit For

End If

Next i

If f = False Then Label1.Caption = "查无此数"

7.对分查找

Dim Key As Integer

Dim f As Boolean

f = False

i = 1

j = 5

Key = Val(Text1.Text)

Do While i

m = Fix((i + j) / 2)

If a(m) = Key Then

Label1.Caption = Str(a(m)) + "已找到"

f = True

Exit Do

End If

If Key

j = m - 1

Else

i = m + 1

End If

Loop

If f = False Then Label1.Caption = "查无此数"

8.递归算法

Function dg(w As Integer) As Long

If w

dg = 1

Else

dg = w * dg(w - 1)

End If

End Function

Private Sub Command5_Click()

Dim s As Long

s = dg(Val(Text1.Text))

Label1.Caption = Str(s)

End Sub

• 发表于:
• 原文链接https://kuaibao.qq.com/s/20180804A0CAB200?refer=cp_1026
• 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。
• 如有侵权，请联系 cloudcommunity@tencent.com 删除。

2022-08-09

2022-08-09

2022-08-09

2022-08-09

2022-08-09

2022-08-09