vb编程大题:随机产生20个10~99的正整数,用冒泡法求出最大值,最小值

“随机产生10~99的一位数组,求出相邻差最大值” 这道题也不会,求解!!!

Option Explicit

Dim myvalue(19) As Integer

Private Sub Command1_Click() '单击按钮开始冒泡法
Dim i As Integer, y As Integer, temp As Integer
For i = 0 To 18
For y = i + 1 To 19
If myvalue(i) > myvalue(y) Then
temp = myvalue(i)
myvalue(i) = myvalue(y)
myvalue(y) = temp
End If
Next y
Next i
Label1.Caption = myvalue(0) '最小值
Label2.Caption = myvalue(19) '最大值
End Sub

Private Sub Command2_Click() '单击清空
Label1.Caption = ""
Label2.Caption = ""
Label3.Caption = ""
Label4.Caption = ""
End Sub

Private Sub Command3_Click() '单击产生随机数
Dim i As Integer
Randomize
For i = 0 To 19
myvalue(i) = Int((90 * Rnd) + 10) '随机产生20~99的整数
Label3.Caption = Label3.Caption & myvalue(i) & "," '列出所有的数
Next i
End Sub

Private Sub Command4_Click() '单击产生相邻的最大差值
Dim i As Integer, a As Integer, b As Integer
b = 0
For i = 0 To 18
a = myvalue(i) - myvalue(i + 1)
If a > b Then b = a
Next i
Label4.Caption = b
End Sub
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网