43 lines
899 B
Plaintext
43 lines
899 B
Plaintext
' FB 1.05.0 Win64
|
|
|
|
Function Mean(array() As Double) As Double
|
|
Dim length As Integer = Ubound(array) - Lbound(array) + 1
|
|
If length = 0 Then
|
|
Return 0.0/0.0 'NaN
|
|
End If
|
|
Dim As Double sum = 0.0
|
|
For i As Integer = LBound(array) To UBound(array)
|
|
sum += array(i)
|
|
Next
|
|
Return sum/length
|
|
End Function
|
|
|
|
Function IsNaN(number As Double) As Boolean
|
|
Return Str(number) = "-1.#IND" ' NaN as a string in FB
|
|
End Function
|
|
|
|
Dim As Integer n, i
|
|
Dim As Double num
|
|
Print "Sample input and output"
|
|
Print
|
|
Do
|
|
Input "How many numbers are to be input ? : ", n
|
|
Loop Until n > 0
|
|
Dim vector(1 To N) As Double
|
|
Print
|
|
For i = 1 to n
|
|
Print " Number #"; i; " : ";
|
|
Input "", vector(i)
|
|
Next
|
|
Print
|
|
Print "Mean is"; Mean(vector())
|
|
Print
|
|
Erase vector
|
|
num = Mean(vector())
|
|
If IsNaN(num) Then
|
|
Print "After clearing the vector, the mean is 'NaN'"
|
|
End If
|
|
Print
|
|
Print "Press any key to quit the program"
|
|
Sleep
|