Given three real numbers, its arithmetic mean (average), geometric mean and harmonic mean are defined as follows:
Write a program to compute and display the means of three REAL variables initialized with positive real values.
Click here to download this program.! ------------------------------------------------------- ! Computes arithmetic, geometric and harmonic means ! ------------------------------------------------------- PROGRAM ComputeMeans IMPLICIT NONE REAL :: X = 1.0, Y = 2.0, Z = 3.0 REAL :: ArithMean, GeoMean, HarmMean WRITE(*,*) 'Data items: ', X, Y, Z WRITE(*,*) ArithMean = (X + Y + Z)/3.0 GeoMean = (X * Y * Z)**(1.0/3.0) HarmMean = 3.0/(1.0/X + 1.0/Y + 1.0/Z) WRITE(*,*) 'Arithmetic mean = ', ArithMean WRITE(*,*) 'Geometric mean = ', GeoMean WRITE(*,*) 'Harmonic Mean = ', HarmMean END PROGRAM ComputeMeans
Data items: 1., 2., 3. Arithmetic mean = 2. Geometric mean = 1.81712067 Harmonic Mean = 1.63636363
The parenthesis surrounding X * Y * Z cannot be removed; otherwise, the expression X * Y * Z **(1.0/3.0) means X * Y * (Z **(1.0/3.0)) since ** has a priority higher than that of *.