2008年12月17日 星期三

求最大值最小值

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '最大值
        Dim i
        Dim a() = {2, 4, 5, 1, 3}
        Dim aMax = a(0)
        For i = 2 To 4
            If a(i) > aMax Then aMax = a(i)
        Next
        MsgBox("最大值:" & aMax)

        'aMin 最小值
        Dim aMin = a(0)
        For i = 2 To 4
            If a(i) < aMin Then aMin = a(i)
        Next
        MsgBox("最小值:" & aMin)
    End Sub
End Class

沒有留言: