PROGRAM salaries_calculation IMPLICIT NONE INTEGER, DIMENSION(9) :: salaries = & (/10500,16140,22300,15960,14150,12180,13230,15760,31000/) INTEGER, DIMENSION(9) :: category = (/1,2,3,2,1,1,1,2,3/) REAL, DIMENSION(3) :: increment = (/.05,.04,.02/) REAL :: sumsal sumsal = 0.0 DO I = 1, 9 sumsal = sumsal + salaries(I) * increment(category(I)) END DO PRINT*, 'Cost of increase (DO loop method) = ', sumsal END PROGRAM salaries_calculation
or, using array notation / intrinsics,
PROGRAM salaries_calculation2 IMPLICIT NONE INTEGER, DIMENSION(9) :: salaries = & (/10500,16140,22300,15960,14150,12180,13230,15760,31000/) INTEGER, DIMENSION(9) :: category = (/1,2,3,2,1,1,1,2,3/) REAL, DIMENSION(3) :: increment = (/.05,.04,.02/) REAL :: sumsal sumsal = SUM(salaries * increment(category)) PRINT*, 'Cost of increase = ', sumsal END PROGRAM salaries_calculation2