'Program Listing SUMARRAY.BAS  contains a FUNCTION called SumArray!
'that calculates the sum of an array.  The main program then uses the sum
'to calculate the mean of the array's values.

DECLARE FUNCTION SumArray! (NumArray!())
REM ** Find Mean of Array Elements **

REM ** Main Program **
' Initialize
DEFINT A-Z
CLS

'Get entries and dimension array
INPUT "Number of enteries"; number
DIM NumArray!(1 TO number)           'Dynamic dimension
FOR element = 1 TO number
  PRINT "Element #"; element;
  INPUT NumArray!(element)
NEXT element

' Call Function, calculate mean
Sum! = SumArray!(NumArray!())
PRINT Sum! / number
PRINT "Please Wait...": SYSTEM

FUNCTION SumArray! (NumArray!())
  FOR item = LBOUND(NumArray!) TO UBOUND(NumArray!)
    total! = total! + NumArray!(item)
  NEXT item
  SumArray! = total!
END FUNCTION

