PROGRAM max ! ! Filename: max.f90 ! ! Author: Br. David Carlson ! ! Date: Feb 6, 2014 ! ! This program prompts the user for the number of reals to be read in ! and then prompts for each real. The program finds the maximum of these ! reals and where it occurs in this list. It then prints the maximum ! real and where it occurs (its position in the list of input). ! If there is a tie for the max, the program finds the first one. IMPLICIT NONE INTEGER::count, k, location REAL::number, maximum WRITE (*, *) 'Enter the number of items to be processed' READ (*, *) count IF (Count < 1) THEN WRITE (*, *) 'You must use at least 1 data item.' ELSE WRITE (*, *) 'Enter your first real value:' READ (*, *) number location = 1 maximum = number DO k = 2, Count WRITE (*, *) 'Enter a real value:' READ (*, *) number IF (number > maximum) THEN ! We have found a better maximum. maximum = number location = k END IF END DO WRITE (*, *) WRITE (*, *) 'Maximum was ', maximum WRITE (*, *) 'Location in input list was ', location END IF END PROGRAM