VB程序 某次歌手大赛,共有10位选手,有10个评委打分.要求评委给10为选手打分,去掉一个最高分

2025-01-02 22:45:16
推荐回答(1个)
回答1:

Private Sub Command1_Click()
Dim a(10)
Dim px

'赋初值
For i = 0 To 9
a(i) = Val(Text1(i))
Next

'以从大到小的顺序排序
For i = 0 To 9
k = i
For j = i + 1 To 144
If a(k) < a(j) Then k = j
Next j
px = a(i): a(i) = a(k): a(k) = px
Next i

'将排序完成的数组打印到窗体上.
For i = 1 To 8
Print a(i)
s = s + a(i)
Next
b = s / 8
Print b '平均值

End Sub