PROGRAM sqroot
!
! Author:  Br. David Carlson
!
! Date:  March 2, 2000
!
! This program prompts the user for the number of floats to be read in
! and then prompts for each float.  The program stores these floats in an
! array, and then prints a table showing each number and its square root
! (unless the number is negative, in which case an error message is shown).

IMPLICIT NONE

INTEGER, PARAMETER::max = 8

REAL, DIMENSION(max)::item
REAL::root
INTEGER::count, k

WRITE (*, *) 'Enter the number of items to be processed'
READ (*, *) count

! Note that no check was made to see if count > max.
! That means that the program could try to enter more numbers than fit
! in the array.  You may get away with it, but it can cause strange
! run-time errors.

DO k = 1, count
   WRITE (*, *) 'Enter a float'
   READ (*, *) item(k)
END DO

WRITE (*, *)
WRITE (*, *) 'Table of items and their square roots:'

DO k = 1, count
   IF (item(k) < 0.0) THEN
      WRITE (*, 100) item(k), 'no real square root'
   ELSE
      WRITE (*, 200) item(k), SQRT(item(k))
   END IF
END DO

100 FORMAT (' ', T5, F12.4, T20, A)
200 FORMAT (' ', T5, F12.4, T20, F12.4)

END PROGRAM

