PROGRAM Complex_Quadratic_Equations !----------------------------------------------------------------------- ! Program to solve a quadratic equation having complex coefficients ! using the quadratic formula. Variables used are: ! A, B, C : the coefficients of the quadratic equation ! Discriminant : the discriminant, B ** 2 - 4 * A * C ! Root_1, Root_2 : the two roots of the equation ! Response : user response to "more data" query ! ! Input: The coefficients A, B, and C ! Output: The two roots of the equation !----------------------------------------------------------------------- IMPLICIT NONE CHARACTER(1) :: Response COMPLEX :: A, B, C, Discriminant, Root_1, Root_2 DO ! Get the coefficients PRINT *, "Enter the coefficients of the quadratic equation as" PRINT *, "complex numbers of the form (a, b):" READ *, A, B, C ! Calculate the discriminant Discriminant = SQRT(B**2 - 4.0*A*C) ! Find the roots Root_1 = (-B + Discriminant) / (2.0 * A) Root_2 = (-B - Discriminant) / (2.0 * A) PRINT *, "The roots are:" PRINT '(5X, F7.3, " +", F7.3, "I")', Root_1, Root_2 WRITE (*, '(/ 1X, A)', ADVANCE = "NO") "More data (Y or N)? " READ *, Response IF (Response == "N") EXIT END DO END PROGRAM Complex_Quadratic_Equations