vb程序设计“生成10个二位数,求出其中的最大值、最小值、平均值,并指出最大最小值是第几个随机数”
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 08:25:23
vb程序设计“生成10个二位数,求出其中的最大值、最小值、平均值,并指出最大最小值是第几个随机数”
vb程序设计“生成10个二位数,求出其中的最大值、最小值、平均值,并指出最大最小值是第几个随机数”
vb程序设计“生成10个二位数,求出其中的最大值、最小值、平均值,并指出最大最小值是第几个随机数”
Private Sub Command2_Click()
Dim a(11) As Integer,s As String
Dim i As Integer,m1 As Integer,m2 As Integer,av As Double,sum As Integer 'm1 最大值,m2最小值
Dim H As Integer,L As Integer
Randomize
H = 1
L = 1
sum = 0
For i = 1 To 10
a(i) = Int(89 * Rnd + 10)
If i = 1 Then
m1 = a(1)
m2 = a(1)
End If
If m1 < a(i) Then
m1 = a(i)
H = i
End If
If m2 > a(i) Then
m2 = a(i)
L = i
End If
sum = sum + a(i)
s = s & " " & a(i)
If i Mod 5 = 0 Then
s = s & Chr(13)
End If
Next i
av = sum / 10
Print
Print "随机数为:" & Chr(13) & s
Print "平均值为:" & av & Chr(13) & "最大数:" & m1 & ",是第" & H & "个随机数" & Chr(13) & "最小数:" & m2 & ",是第" & L & "个随机数"
End Sub