怎样 随机生成20个60--100间的整数,计算其总和,平均值(保留三位小数),最大值并输出 ????
知道的告我一声,谢谢了
Private Sub Command1_Click()
Dim a(19) As Integer
Dim sum As Integer
Dim i As Integer
Dim avga As Single
Dim max As Integer
max = 0: sum = 0
For i = 0 To 19
a(i) = Int(40 * Rnd) + 60
sum = sum + a(i)
If max < a(i) Then
max = a(i)
End If
Next i
avga = sum / 20
Print sum
Print max
Print Format(avga, "##.##")
End Sub
Private Sub Command1_Click()
Dim arrVal(19) As Integer
Dim iCount As Integer
Dim iTotal As Integer
Dim ibuf As Integer
Dim iMax As Integer
Do While iCount < 20
ibuf = Int(Rnd(iCount + ibuf) * 100)
If ibuf >= 40 Then
arrVal(iCount) = ibuf
If iMax < ibuf Then iMax = ibuf
iTotal = iTotal + ibuf
Debug.Print ibuf
iCount = iCount + 1
End If
Loop
Debug.Print "总计=" & iTotal
Debug.Print "最大值=" & iMax
Debug.Print "平均值=" & Format(Int((iTotal / 20) * 1000) / 1000, "###.000")
End Sub