C     Last change:  X     5 Oct 2004    3:15 pm
!     Last change:  X     5 Oct 2004    2:46 pm
PROGRAM Mean_of_a_list_lab5_formatted
!
! Use a 1-D compile-time array and function call and formatted output
!
IMPLICIT NONE
INTEGER :: i
INTEGER, PARAMETER :: NumGrades = 10
REAL, DIMENSION(NumGrades) :: Grades

WRITE (*,'(2X, A, I3, A)') "Enter the ", NumGrades, " real numbers: "
READ (*,*)Grades

! output scores in two different ways
! 3 spots allocated for integer
! 6 spots for real (including decimal point) and 2 of those are for the fractional part
DO i=1, NumGrades
   WRITE(*,'(2X, A, I3, A, F6.2)') "Score ", i, " is ", Grades(i)
END DO
WRITE(*,'(2X, A, 10F6.2)') "The scores are ", Grades

WRITE (*,'(2X, A, I3, A, F6.2)') "The mean of the ", NumGrades, " scores is ", Mean(Grades, NumGrades)

STOP
CONTAINS

!-Mean function defined below-----------------------------

FUNCTION Mean(X, NumElements)

   INTEGER, INTENT(IN) :: NumElements
   REAL, DIMENSION(NumElements), INTENT(IN) :: X
   REAL :: Mean

   Mean = SUM(X)/ REAL(NumElements)

RETURN
END FUNCTION Mean

END PROGRAM Mean_of_a_list_lab5_formatted

