VB程序歌曲大奖赛中,有10个评委进行打分,试编程求这位选手的平均得分(要求:去掉一个最 5
歌曲大奖赛中,有10个评委进行打分,试编程求这位选手的平均得分(要求:去掉一个最高分和一个最低分)排序题PrivateSubForm_Click()Dima(10)AsI...
歌曲大奖赛中,有10个评委进行打分,试编程求这位选手的平均得分(要求:去掉一个最高分和一个最低分)排序题
Private Sub Form_Click()
Dim a(10) As Integer
Dim t As Integer, s As Integer
Dim v As Single
For i = 1 To 10
a(i) = InputBox("a(" & i & ")=")
Next i
这里开始的是乱序的,帮忙顺序排序一下
For i = 1 To 9
For j = i + 1 To 10
t = a (i)
End Sub
a(j) = t
End If
Print "平均得分="; v
Next j
a(i) = a(j)
Next i
s=0
For i = 2 To 9
If a (i) > a (j) Then
s = s + a(i)
Next i
v = s / 8 展开
Private Sub Form_Click()
Dim a(10) As Integer
Dim t As Integer, s As Integer
Dim v As Single
For i = 1 To 10
a(i) = InputBox("a(" & i & ")=")
Next i
这里开始的是乱序的,帮忙顺序排序一下
For i = 1 To 9
For j = i + 1 To 10
t = a (i)
End Sub
a(j) = t
End If
Print "平均得分="; v
Next j
a(i) = a(j)
Next i
s=0
For i = 2 To 9
If a (i) > a (j) Then
s = s + a(i)
Next i
v = s / 8 展开
2个回答
展开全部
'使用下面的代码不需要排序评委打分即可得出去除最高分和最低分之后的平均分
Private Sub Form_Click()
Dim a(10) As Integer, i As Integer
Dim max As Integer, min As Integer, sum As Long
max = -1 '最低分为0分
For i = 1 To 10
a(i) = InputBox("评委" & i & "打分=")
sum = sum + a(i)
If i = 2 Then
If a(i) <= max Then
min = a(i)
Else
max = a(i)
min = a(i - 1)
End If
Else
If a(i) > max Then
max = a(i)
ElseIf a(i) < min Then
min = a(i)
End If
End If
Next
Print "平均得分 = " & Replace(Replace(Format((sum - max - min) / 8, "0.00分"), "0分", "分"), ".0分", "分")
End Sub
Private Sub Form_Click()
Dim a(10) As Integer, i As Integer
Dim max As Integer, min As Integer, sum As Long
max = -1 '最低分为0分
For i = 1 To 10
a(i) = InputBox("评委" & i & "打分=")
sum = sum + a(i)
If i = 2 Then
If a(i) <= max Then
min = a(i)
Else
max = a(i)
min = a(i - 1)
End If
Else
If a(i) > max Then
max = a(i)
ElseIf a(i) < min Then
min = a(i)
End If
End If
Next
Print "平均得分 = " & Replace(Replace(Format((sum - max - min) / 8, "0.00分"), "0分", "分"), ".0分", "分")
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询