!
! =====> Program - P52.F90
!
!
! Nested loops to access arrays
!
CHARACTER (LEN=3) :: MONTH(12)
INTEGER UNITS(12)
REAL SALES(12)
!
!
PRINT *, 'This is Program >> P52 - Nested loops for arrays'
!
! Tell program where data for READ * is coming from
OPEN(UNIT=5, FILE='P52.DAT') ! UNIT=5 is the default input
!
!
L1: DO I=1,12
READ 15,MONTH(I),UNITS(I),SALES(I)
END DO L1
15 FORMAT(A3,I7,F5.1)
I=0
L2: DO J=1,4 ! Four quarters
NQ=0
SQ=0
L3: DO K=1,3 ! Each with three months
I=I+1 ! Month pointer I goes from 1 to 12
NQ=NQ+UNITS(I)
SQ=SQ+SALES(I)
END DO L3
PRINT 25,J,NQ,SQ
25 FORMAT(' QUARTER',I2, &
I7,' CARS $',F5.1,' M')
END DO L2
STOP
END
OUTPUT:
Program entered
This is Program >> P42 - Nested DO loops
1 5050 1
3 10097 4
5 15137 9
7 20166 16
9 25180 25
11 30175 36
13 35147 49
15 40092 64
17 45006 81
19 49885 100
21 54725 121
23 59522 144
25 64272 169
27 68971 196
29 73615 225
31 78200 256
33 82722 289
35 87177 324
37 91561 361
39 95870 400
41 100100 441
43 104247 484
45 108307 529
47 112276 576
49 116150 625
51 119925 676
53 123597 729
55 127162 784
57 130616 841
59 133955 900
61 137175 961
63 140272 1024
65 143242 1089
67 146081 1156
69 148785 1225
71 151350 1296
73 153772 1369
75 156047 1444
77 158171 1521
79 160140 1600
81 161950 1681
83 163597 1764
85 165077 1849
87 166386 1936
89 167520 2025
91 168475 2116
93 169247 2209
95 169832 2304
97 170226 2401
99 170425 2500
Fortran-90 STOP
Page builder: Charles Boivin
Last modified: 11/07/95