VB 随机产生10个0~100之间的随机整数,去掉最大值与最小值,剩下8个数的和与平均数.VB
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/07 22:40:18
VB 随机产生10个0~100之间的随机整数,去掉最大值与最小值,剩下8个数的和与平均数.VB
VB 随机产生10个0~100之间的随机整数,去掉最大值与最小值,剩下8个数的和与平均数.
VB
VB 随机产生10个0~100之间的随机整数,去掉最大值与最小值,剩下8个数的和与平均数.VB
帮你写好了,这个是工程文件,下载下来就可以了.
以下是源码:
Private Sub Command1_Click()
Dim A(10) As Double, L As Integer, B As Double, C As Double, D As Double
Randomize '根据时间初始化随机数
A(0) = (Rnd * 100)
A(1) = (Rnd * 100)
A(2) = (Rnd * 100)
A(3) = (Rnd * 100)
A(4) = (Rnd * 100)
A(5) = (Rnd * 100)
A(6) = (Rnd * 100)
A(7) = (Rnd * 100)
A(8) = (Rnd * 100)
A(9) = (Rnd * 100)
B = 0
For L = 0 To 9 '取出最大值
If B < A(L) Then B = A(L)
Next
C = 100
For L = 0 To 9 '取出最大值
If C > A(L) Then C = A(L)
Next
For L = 0 To 9 '将所有数相加
D = D + A(L)
Next
D = D - B - C '去除最大和最小值
D = D / 8 '算出平均值
MsgBox "未进行四舍五入前:" & D
MsgBox "保留小数2位:" & Round(D, 2)
End Sub