Quadratic Equation (Real Roots) | FORTRAN 95

PROGRAM qe
IMPLICIT NONE

!declaring variables

REAL::a,b,c,d,root1,root2,val

PRINT *, '============================================'
PRINT *, 'PROGRAM TO CALCULATE ROOTS OF A QUADRATIC EQUATION [REAL ROOTS ONLY] [ BY WWW.BOTTOMSCIENCE.COM ]'
PRINT *, '============================================'

PRINT *,'Please enter the value of cofficients a, b, and c respectively as per the equation - ax^2 + bx + c'

!calculating the square root part -> square root(b^2-4ac)

val=((b**2)-(4*a*c))

d=SQRT(val)

root1=(-b+d)/(2*a)
root2=(-b-d)/(2*a)

PRINT *,'Calculated real roots are - root 1 = ',root1 ,'root 2 = ', root2

END PROGRAM

Share