VB编程:随机产生10个0~100的整数 用选择法从小到大排列 冒泡法从大到小排列
展开全部
新建一个form1添加command1添加label1label1高度设的稍高一点,以显示数据。form代码视图中加入以下语句.Private Sub Command1_Click() '定义变量
Dim a(9) As Integer
Dim i As Integer
Dim r As Integer
Dim t As Integer '产生随机数
Randomize
For i = 0 To 9
a(i) = CInt(Rnd() * 100)
Next i '排序
For i = 0 To 8
For r = i + 1 To 9
If a(i) > a(r) Then
t = a(i)
a(i) = a(r)
a(r) = t
End If
Next r
Next i '显示数据
Label1.Caption = ""
For i = 0 To 9
Label1.Caption = Label1.Caption + "第" + CStr(i + 1) + "个随机数=" + CStr(a(i)) + vbCrLf
Next i
End Sub
Dim a(9) As Integer
Dim i As Integer
Dim r As Integer
Dim t As Integer '产生随机数
Randomize
For i = 0 To 9
a(i) = CInt(Rnd() * 100)
Next i '排序
For i = 0 To 8
For r = i + 1 To 9
If a(i) > a(r) Then
t = a(i)
a(i) = a(r)
a(r) = t
End If
Next r
Next i '显示数据
Label1.Caption = ""
For i = 0 To 9
Label1.Caption = Label1.Caption + "第" + CStr(i + 1) + "个随机数=" + CStr(a(i)) + vbCrLf
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询