重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
vb2010写的:
创新互联建站服务项目包括翁牛特网站建设、翁牛特网站制作、翁牛特网页制作以及翁牛特网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,翁牛特网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到翁牛特省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim str As String = ""
Dim a(30) As Integer
Dim temp As Integer
str = str "生成的30个随机数字是 " vbCrLf
For i = 1 To 30
a(i) = Int(Rnd() * 50 + 1)
str = str a(i) " "
If i Mod 10 = 0 Then
str = str vbCrLf
End If
Next
str = str vbCrLf
For i = 1 To 30
For j = 1 To 30 - i
If a(j) a(j + 1) Then
temp = a(j + 1)
a(j + 1) = a(j)
a(j) = temp
End If
Next j
Next i
str = str "排序后的数字是 " vbCrLf
For i = 1 To 30
str = str a(i) " "
If i Mod 10 = 0 Then
str = str vbCrLf
End If
Next
TextBox6.Text = str
End Sub
运行结果:
生成的30个随机数字是
36 27 29 15 16 39 1 39 41 36
3 21 44 40 19 49 44 3 48 19
27 39 3 30 24 15 32 33 14 14
排序后的数字是
49 48 44 44 41 40 39 39 39 36
36 33 32 30 29 27 27 24 21 19
19 16 15 15 14 14 3 3 3 1
Private Sub Command1_Click()
Dim a(1 To 100) As Integer
Dim i As Integer, j As Integer, k As Integer
For i = 1 To 100 '给数组a一百个元素赋值,并换每行十个数字输出来窗体上
a(i) = Int(Rnd * 101)
k = k + 1
Print Tab((k - 1) * 5); a(i);
If k = 10 Then k = 0: Print
Next i
For i = 100 To 2 Step -1 '用冒泡排序法对数组进行排序
For j = 1 To i - 1
If a(j) a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
For i = 1 To 100 '输出排好序的数组
k = k + 1
Print Tab((k - 1) * 5); a(i);
If k = 10 Then k = 0: Print
Next i
End Sub
给你一个最简单的冒泡排序代码:
将三个数放到一个数组中。
a(0)=val(text1.text):a(1)=val(text2.text):a(2)=val(text3.text)
dim flag as Boolean,temp as Integer
for i = 0 to 2
flag = true
for j = 2 to 1
if a(j)a(j-1) then
temp = a(j-1)
a(j-1) = a(j)
a(j) = temp
flag = false
end if
next j
if flag then Exit For
next i
text4.text=a(0):text5.text=a(1):text6.text=a(2)