Skip to content

Instantly share code, notes, and snippets.

@Ansarina
Last active October 24, 2015 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ansarina/6cd8de8c484a215b9344 to your computer and use it in GitHub Desktop.
Save Ansarina/6cd8de8c484a215b9344 to your computer and use it in GitHub Desktop.
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