# P54.F90

### Array Max, Min, Avg

```!
! =====> Program - P54.F90
!
CHARACTER (LEN=3) :: MONTH(12)
INTEGER  UNITS(12),UQ(4)
REAL     SALES(12),DQ(4)
!
!
PRINT *, 'This is Program >> P54  - Array Max, Min, Average'
!
!     Tell program where data for  READ *  is coming from
OPEN(UNIT=5, FILE='P54.DAT')      ! UNIT=5 is the default input
!
!
L1:   DO I=1,12
END DO L1
202   FORMAT(A3,I7,F5.1)
!
NCARS=UNITS(1)
TOTALS=SALES(1)
SBIG=TOTALS  ! Set biggest to the first one
SMIN=TOTALS  ! Set smallest to the first one
MINS=1
MAXS=1
!
!     Loop through the arrays and find max and min
!     and totals
L2:   DO I=2,12
NCARS=NCARS+UNITS(I)
TOTALS=TOTALS+SALES(I)
IF(SALES(I) > SBIG)THEN
SBIG=SALES(I)
MAXS=I  ! Remember position of biggest
ELSE IF(SALES(I) < SMIN)THEN
SMIN=SALES(I)
MINS=I  ! Remember position of smallest
ENDIF
END DO L2
!
!     Form the totals by quarter
!
I=0
L3:   DO J=1,4
UQ(J)=0
DQ(J)=0
L4:      DO K=1,3
I=I+1
UQ(J)=UQ(J)+UNITS(I)
DQ(J)=DQ(J)+SALES(I)
END DO L4
END DO L3
!
!      OUTPUT ORIGINAL DATA + RESULTS
!
PRINT 501
501   FORMAT(//'MONTH UNIT', &
'  SALES M\$'/)
L4:   DO K=1,12
PRINT 503,MONTH(K),UNITS(K),SALES(K)
END DO L4
503   FORMAT(3X,A3,I6,F6.1)
PRINT 504,NCARS,TOTALS
504   FORMAT(/' TOTALS',I5,F6.1)
NAVE=NCARS/12
TAVE=TOTALS/12.0
PRINT 505,NAVE,TAVE
505   FORMAT(/' AVE.',I7,F6.1)
PRINT 506,SBIG,SMIN      ! Biggest and smallest values and
PRINT 507,MONTH(MAXS),MONTH(MINS)  ! corresponding months
506   FORMAT(/'BEST/WORST-',2F7.1)
507   FORMAT(/'OCCURED IN ',2(4X,A3))
PRINT 530,UQ
PRINT 531,DQ
530   FORMAT(/'CARS SOLD BY QUARTER',4I8)
531   FORMAT('SALES BY QUARTER    ',4F8.1)
STOP
END

DATA:
JAN    672 3.4
FEB    609 3.2
MAR    715 3.7
APR    803 4.2
MAY    810 4.8
JUN    831 5.1
JUL    829 5.1
AUG    727 5.1
SEP    780 4.3
OCT    703 3.9
NOV    791 4.2
DEC    783 3.6

OUTPUT:
Program entered
This is Program >> P54  - Array Max, Min, Average

MONTH UNIT  SALES M\$

JAN   672   3.4
FEB   609   3.2
MAR   715   3.7
APR   803   4.2
MAY   810   4.8
JUN   831   5.1
JUL   829   5.1
AUG   727   5.1
SEP   780   4.3
OCT   703   3.9
NOV   791   4.2
DEC   783   3.6

TOTALS 9053  50.6

AVE.    754   4.2

BEST/WORST-    5.1    3.2

OCCURED IN     JUN    FEB

CARS SOLD BY QUARTER    1996    2444    2336    2277
SALES BY QUARTER        10.3    14.1    14.5    11.7
Fortran-90 STOP
```

Come back to the previous page

Page builder: Charles Boivin