Skip to content

Instantly share code, notes, and snippets.

@mooncos
Created October 15, 2018 19:59
Show Gist options
  • Save mooncos/28f89c6a2f7a3ff443b8f57edc9ca9ef to your computer and use it in GitHub Desktop.
Save mooncos/28f89c6a2f7a3ff443b8f57edc9ca9ef to your computer and use it in GitHub Desktop.
Program that calculates the solutions to a 2nd degree equation of complex numbers
PROGRAM Q_1
implicit none
complex :: a, b, c !! coefficients
complex :: x1, x2 !! solutions
write (*,*) "Enter a, b, c complex values"
read (*,*) a, b, c
write (*,*) "Using values a=", a, "b=", b, "c=", c
if (a==0) then
if (b==0) then
write (*,*) "There is no solution"
else
write (*,*) "There is only one solution x1=", -c/b
end if
else
x1 = (-b + sqrt (b**2 - 4*a*c) ) / (2*a)
x2 = (-b - sqrt (b**2 - 4*a*c) ) / (2*a)
write (*,*) "There are two solutions x1=", x1, "and x2=", x2
end if
read(*,*)
write (*,*) "Program terminated"
end program Q_1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment