'如出現雜訊,請改以Chrome 開啓
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim na() = {"趙一", "李四", "張三", "李四", "王五", "方六"}
Dim ch() = {90, 60, 100, 75, 50, 80}
Dim msg = ""
'平均
Dim s = 0
For i = 0 To 5
s = s + ch(i)
Next
msg = msg & "平均:" & Int(s / 6 + 0.5) & "分" & vbNewLine
'最高分
Dim ma = ch(0)
Dim t = ""
For i = 1 To 5
If ch(i) > ma Then
ma = ch(i)
t = na(i)
End If
Next
msg = msg & "最高分:" & ma & "分是" & t & vbNewLine
'最低分
Dim mi = ch(0)
For i = 1 To 5
If ch(i) < mi Then
mi = ch(i)
t = na(i)
End If
Next
msg = msg & "最低分:" & mi & "分是" & t & vbNewLine
'李四考幾分?
For i = 0 To 5
If na(i) = "李四" Then
msg = msg & "李四考" & ch(i) & "分" & vbNewLine
End If
Next
'80分以上有多少人?
msg = msg & vbNewLine
Dim c = 0
For i = 0 To 5
If ch(i) >= 80 Then
c = c + 1
End If
Next
msg = msg & "80分以上有" & c & "人" & vbNewLine
'80分以上有誰?
For i = 0 To 5
If ch(i) >= 80 Then
msg = msg & na(i) & "考" & ch(i) & "分" & vbNewLine
End If
Next
msg = msg & vbNewLine
'國文成績大於平均分數5分以上有誰?
For i = 0 To 5
If ch(i) >= Int(s / 6 + 0.5) + 5 Then
msg = msg & na(i) & "考" & ch(i) & "分-->大於平均(平均:" & Int(s / 6 + 0.5) & ")5分以上" & vbNewLine
End If
Next
MsgBox(msg)
End
End Sub
End Class
沒有留言:
張貼留言