Module Module1
'Returns the mean average of the 3 statistics
'A(0) contains the Min
'A(2) contains the Max
'A(1) contain the Median
Public Function Stats3(A() As Integer)
Dim meanAvg As Double
Dim iTemp As Integer
meanAvg = (A(0) + A(1) + A(2)) * 1.0 / 3
'Bubble Sorts the array
If A(0) > A(1) Then
iTemp = A(0)
A(0) = A(1)
A(1) = iTemp
End If
If A(1) > A(2) Then
iTemp = A(1)
A(1) = A(2)
A(2) = iTemp
End If
If A(0) > A(1) Then
iTemp = A(0)
A(0) = A(1)
A(1) = iTemp
End If
'Returns the average
Stats3 = meanAvg
End Function
Sub Go(A() As Integer)
Dim meanAvg As Double
meanAvg = Stats3(A)
Console.WriteLine("**************************")
Console.WriteLine("The min is " & A(0))
Console.WriteLine("The max is " & A(2))
Console.WriteLine("The median is " & A(1))
Console.WriteLine("The mean average is " & meanAvg)
Console.WriteLine("*****************************")
Console.WriteLine("Press key...")
Console.ReadKey()
End Sub
Sub Main()
Dim A() = {5, 12, 20}
Go(A)
End Sub
End Module
----------------------------------
output is:
**************************
The min is 5
The max is 20
The median is 12
The mean average is 12.3333333333333
*****************************
Press key...