PROGRAM quadeq1
!
! Author:  Br. David Carlson
!
! Date:  January 3, 2000
!
! Revised:  May 2, 2004, Feb 3, 2008, and Feb 16, 2008
!
! This program prints out the real solution(s) to a quadratic equation.
! The user is prompted to input the coefficents a, b, c of the quadratic
! equation.  The standard quadratic formula is used.
! Try it for a = 1.0, b = -1.0E6, c = 1.0.  Solutions should be 1.0E6 and 1.0E-6
! approximately.  Compare with quadeq2.f90.  Just for fun, try a = 0 (illegal),
! b = 1, c = 2.

IMPLICIT NONE

REAL::a, b, c, discriminant, root

WRITE (*, 20)
20 FORMAT (1X, ' Program to find real solutions of a quadratic equation')

WRITE (*, *) 'Enter (nonzero) coefficient a: '
READ (*, *) a

WRITE (*, *) 'Enter coefficient b: '
READ (*, *) b

WRITE (*, *) 'Enter coefficient c: '
READ (*, *) c

discriminant = b * b - 4.0 * a * c

IF (discriminant < 0) THEN
   WRITE (*, *) ' No real solutions'
ELSE IF (discriminant == 0) THEN
   WRITE (*, *) ' One real solution: ', -b / (2.0 * a)
ELSE
   root = SQRT(discriminant)
   WRITE (*, *) ' Two real solutions: ', (-b + root) / (2.0 * a),   &
      ' and ', (-b - root) / (2.0 * a)
END IF

END PROGRAM

