Task

Create a function that returns the maximum value in a provided set of values,

where the number of values may not be known until run-time.




' FB 1.05.0 Win64
 
Function MaxElement(a() As Double) As Double
  Dim max As Double = a(LBound(a))
  For i As Integer = LBound(a) + 1 To UBound(a)
    If a(i) > max Then max = a(i)
  Next
  Return max
End Function
 
Dim As Integer i, n
Input "How many values are to be input ";  n
If n < 1 Then End
Dim a(1 To n) As Double
For i = 1 To n
  Print "  Value"; i; " : ";
  Input "", a(i)
Next
Dim max As Double = MaxElement(a())
Print
Print "The greatest value is"; max
Print
Print "Press any key to quit"
Sleep
 