      PROGRAM AVE2
************************************************************************
* 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, LIMIT, NUM)
100   FORMAT(1X, 'MEAN OF THE ', I3, ' NUMBERS IS ', F6.2)
      END


**MEAN******************************************************************
* Function to find the mean of first N elements of the array X of      *
* dimension XLIM.  The actual dimension is passed to the subprogram    *
* by the actual argument corresonding to XLIM.   Local variables       *
* used are:                                                            *
*     SUM    : sum of the numbers                                      *
*     I      : subscript                                               *
*                                                                      *
* Accepts:  Array X and integers XLIM and N                            *
* Returns:  The mean of the N numbers stored in X                      * 
************************************************************************

      FUNCTION MEAN(X, XLIM, N)

      INTEGER XLIM, N, I
      REAL MEAN, X(XLIM), SUM

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

