求最大值与最小值
题目:输入n个分数,去除一个最大值和一个最小值,得出平均数,作为运动员的最终得分Private Sub Command1_Click()
Const n = 10
Dim a(n), sum, ave, max, min As Double
Dim i As Integer
sum = 0
For i = 1 To n
a(i) = InputBox("请输入第" & i & "个成绩:", "输入")
sum = sum + a(i)
Print a(i)
Next
max = a(1)
min = a(1)
For i = 1 To n
If max < a(i) Then
max = a(i)
End If
If min > a(i) Then
min = a(i)
End If
Next
Print "最大值为"; max; " "; "最小值为"; min
sum = sum - max - min
Print "总分为"; sum
ave = sum / (n - 2)
Print "该运动员最终得分为:"; ave;
End Sub
结果输出是----------------------------------------------------------------------
1
2
3
10
4
5
6
7
8
9
最大值为9 最小值为1
总分为 45
该运动员最终得分为: 5.625
-----------------------------------------------------------
怎么最大值不是10呢??是哪里错了??
谢谢~~