! PROGRAM P54 ! IMPLICIT NONE CHARACTER (LEN=3) :: MONTH(12) INTEGER :: I,J,K,UNITS(12),UQ(4),NCARS,MAXS,MINS REAL :: SALES(12),SQ(4),TOTALS,SBIG,SMIN REAL :: NAVE,TAVE ! ! 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 READ 202,MONTH(I),UNITS(I),SALES(I) 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 END IF END DO L2 ! ! Form the totals by quarter ! I=0 L3: DO J=1,4 UQ(J)=0 SQ(J)=0 LOOP: DO K=1,3 I=I+1 UQ(J)=UQ(J)+UNITS(I) SQ(J)=SQ(J)+SALES(I) END DO LOOP 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(' ',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.',F5.1,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(' ',A3)) PRINT 530,UQ PRINT 531,SQ 530 FORMAT(/' CARS SOLD BY QUARTER',4I8) 531 FORMAT(' SALES BY QUARTER ',4F8.1) STOP END PROGRAM P54