Skip to content

Instantly share code, notes, and snippets.

@Ansarina Ansarina/Equation_solver_fortran.f90 Secret
Last active Oct 24, 2015

Embed
What would you like to do?
PROGRAM Equation_solver_fortran
! This is program calculate the real roots of second order equation
IMPLICIT NONE ! this is important to get used to this statment
! Variable decleration
REAL::a,b,c
REAL::Delta, x1, x2
! Main Porgram
WRITE(*,*) "Please enter the equation coefficients a*x^2+b*x+c"
WRITE(*,*) "a: ?"
READ(*,*) a
WRITE(*,*) "b: ?"
READ(*,*) b
WRITE(*,*) "c: ?"
READ(*,*) c
Delta=b**2-4*a*c
IF (Delta >= 0) THEN
x1=(b+SQRT(Delta))/(2*a)
x2=(b-SQRT(Delta))/(2*a)
WRITE(*,*) " The real roots are : ", x1, x2
ELSE
WRITE(*,*) " This equation has no real root!"
ENDIF
PAUSE
END PROGRAM Equation_solver_fortran
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.