Print Means

WARNING: This example assumes the output is sent to a printer, and as a result, every formatted output contains printer control.

Problem Statement

Write a program to print the multiplication table in the following form:
         1    1    2    2    3    3
....5....0....5....0....5....0....5
 Input Data

 a =       1.0000000
 b =       2.0000000
 c =       3.0000000

 Computed Results

 Arithmetic Mean =       2.0000000
 Geometric Mean  =       1.8171207
 Harmonic Mean   =       1.6363636

Solution

PROGRAM  Means
   IMPLICIT  NONE
   REAL                        :: a, b, c
   REAL                        :: Am, Gm, Hm
   CHARACTER(LEN=*), PARAMETER :: FMT = "(1X, A//3(1X, A, F15.7/))"

   READ(*,*) a, b, c
   Am = (a + b + c)/3.0
   Gm = (a * b * c)**(1.0/3.0)
   Hm = 3.0 / (1.0/a + 1.0/b + 1.0/c)
   WRITE(*,FMT) "Input Data",   &
                "a = ", a,      &
                "b = ", b,      &
                "c = ", c
   WRITE(*,FMT) "Computed Results",  &
                "Arithmetic Mean = ", Am, &
                "Geometric Mean  = ", Gm, &
                "Harmonic Mean   = ", Hm

END PROGRAM  Means
Click here to download this program.

Program Input and Output

Suppose we have the following input:
         1    1    2    2    3
....5....0....5....0....5....0
1.0       2.0       3.0
The output of the program is:
         1    1    2    2    3    3
....5....0....5....0....5....0....5
 Input Data

 a =       1.0000000
 b =       2.0000000
 c =       3.0000000

 Computed Results

 Arithmetic Mean =       2.0000000
 Geometric Mean  =       1.8171207
 Harmonic Mean   =       1.6363636

Discussion