!OPEN(S) PROGRAM
PROGRAM QuadraticRoots

!THE FOLLOWING REMOVES THE PRE-EXISTING IMPLICIT TYPE RULE
IMPLICIT NONE

!DECLARATION BLOCK
REAL :: A, B, C      ! Co-efficients of the quadratic equation
REAL :: Discriminant, X1, X2

!INPUT CO-EFFICIENTS
PRINT *, "Enter coefficient A:"
READ *, A
PRINT *, "Enter coefficient B:"
READ *, B
PRINT *, "Enter coefficient C:"
READ *, C

!CALCULATE(S) DISCRIMINANT
Discriminant = B**2 - 4*A*C

!CHECK DISCRIMINANT FOR ROOTS
IF (Discriminant > 0) THEN
   X1 = (-B + SQRT(Discriminant)) / (2*A)
   X2 = (-B - SQRT(Discriminant)) / (2*A)
   PRINT *, "Two real roots: ", X1, " and ", X2
ELSE IF (Discriminant == 0) THEN
   X1 = -B / (2*A)
   PRINT *, "One real root: ", X1
ELSE
   PRINT *, "Complex roots: ", (-B/(2*A)), " + i*", SQRT(ABS(Discriminant))/(2*A), " and ", (-B/(2*A)), " - i*", SQRT(ABS(Discriminant))/(2*A)
END IF

!CLOSE(S) PROGRAM
END PROGRAM QuadraticRoots

! This program prompts the user to enter the coefficients of the quadratic equation (A, B, C) and then calculates the discriminant. Based on the discriminant, it determines and prints the roots of the quadratic equation.

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: