      PROGRAM AVE1
************************************************************************
* Program to read a list of numbers ITEM(1), ITEM(2), ... , ITEM(NUM)  *
* and to calculate their mean using the function subprogram MEAN.      *
* Identifiers used are:                                                *
*     ITEM    : one-dimensional array of numbers                       *
*     LIMIT   : size of array ITEM (parameter)                         *
*     I       : subscript                                              *
*     NUM     : number of items                                        *
*     MEAN    : function that finds the mean of a set of numbers       *
*                                                                      *
* Input:  NUM and a list of NUM real numbers                           *
* Output: the mean of the numbers                                      *
************************************************************************

      INTEGER LIMIT
      PARAMETER (LIMIT = 50)
      REAL ITEM(LIMIT), MEAN
      INTEGER NUM, I

      PRINT *, 'ENTER NUMBER OF ITEMS AND THE ITEMS'
      READ *, NUM, (ITEM(I), I = 1, NUM)
      PRINT 100, NUM, MEAN(ITEM, NUM)
100   FORMAT(1X, 'MEAN OF THE ', I3, ' NUMBERS IS ', F6.2)
      END

**MEAN******************************************************************
* Function to find the mean of the first N elements of the array X of  *
* dimension XLIMIT.  Local variables used are:                         *
*     SUM    : sum of the numbers                                      *
*     I      : subscript                                               *
*                                                                      *
* Accepts:  Array X and integer N                                      *
* Returns:  The mean of the N numbers stored in X                      * 
************************************************************************

      FUNCTION MEAN(X, N)

      INTEGER XLIMIT
      PARAMETER (XLIMIT = 50)
      REAL MEAN, X(XLIMIT), SUM
      INTEGER N, I

      SUM = 0
      DO 10 I = 1, N
          SUM = SUM + X(I)
10    CONTINUE
      MEAN = SUM / REAL(N)
      END

