# Computing and Printing the Input Data and Their Average: Version 3

 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 that reads in a set of values into a REAL array, computes the average, and prints a report like the following:
```         1    1    2    2    3    3    4    4    5
....5....0....5....0....5....0....5....0....5....0
Average Computation

Input Data

100.00    231.00     67.00    179.00    315.00
78.00    111.00    410.00     98.00     25.00
245.00     90.00    101.00    250.00    379.00

Average =   1.7860001E+02
```
This problem is identical to the previous one; however, we want to print the input five items per row as shown above.

### Solution

```PROGRAM  Mean
IMPLICIT  NONE
INTEGER, PARAMETER         :: SIZE = 20
REAL, DIMENSION(1:SIZE)    :: x
INTEGER                    :: ActualSize
INTEGER                    :: i
REAL                       :: Average
CHARACTER(LEN=30)          :: Title = "(A, A)"

READ(*,*)  (x(i), i = 1, ActualSize)

Average = 0.0
DO i = 1, ActualSize
Average = Average + x(i)
END DO
Average = Average / ActualSize

WRITE(*,Title)  " ", "Average Computation"
WRITE(*,Title)  " "
WRITE(*,Title)  " ", "Input Data"
WRITE(*,Title)  " "
WRITE(*,"(5F10.2)")  (x(i), i = 1, ActualSize)
WRITE(*,Title)  " "
WRITE(*,"(A, A,ES15.7)")  " ", "Average = ", Average
END PROGRAM  Mean
```

### Program Input and Output

If the input data consist of the following:
```15
100.0  231.0   67.0  179.0  315.0
78.0  111.0  410.0   98.0   25.0
245.0   90.0  101.0  250.0  379.0
```
The output of the program is:
``` Average Computation

Input Data

100.00    231.00     67.00    179.00    315.00
78.00    111.00    410.00     98.00     25.00
245.00     90.00    101.00    250.00    379.00

Average =   1.7860001E+02
```

### Discussion

• The desired output is the following.
```         1    1    2    2    3    3    4    4    5
....5....0....5....0....5....0....5....0....5....0
100.00    231.00     67.00    179.00    315.00
78.00    111.00    410.00     98.00     25.00
245.00     90.00    101.00    250.00    379.00
```
We see that each number is printed using 10 positions with two positions for the fractional part. This means F10.2. Putting five of them together gives a format "(5F10.2)". Therefore, the WRITE statement should be:
```WRITE(*,"(5F10.2)")  (x(i), i = 1, ActualSize)
```
Note here that the format rescanning rules are used. If the number of input data items is more than 5, then the first line contains x(1) to x(5) and is printed. The format is rescanned and the second line contains x(6) to x(10), and so on.
• Some of you may quickly find out that this format has no printer control. No, there is no explicit printer control; but, it does have an implicit one. The first F10.2 prints a number using the first 10 positions and if the numbers are not large, the first position will contain a space. If the numbers are larger with at least seven digits in the integral part, the width of field of the F edit descriptor must be increased.
• If these data are printed with a printer, since the first position of each line is used for printer control, you could only see 49 positions. Only nine positions of the first number will be shown on your printer output. This problem can be overcome using the following format:
```WRITE(*,"(F11.2,4F10.2)")  (x(i), i = 1, ActualSize)
```
That is, the first F edit descriptor uses 11 positions rather than 10. Thus, an explicit printer control character is incorporated into the first edit descriptor.