program quadratic ! solve a quadratic with real roots ! JWP 22/10/98 implicit none real :: a, b, c, d, x, x1, x2 ! a = 1 b = 2 c = -3 ! print *, 'Solving quadratic:' print *, a, ' x**2 +', b, ' x + ', c ! check nature of roots.. ! d = b**2 - 4.0*a*c ! if (d<0) then print *, 'Has complex roots.' else x1 = (-b + sqrt(d)) / 2.0 / a x2 = (-b - sqrt(d)) / 2.0 / a print *, 'Roots are:', x1, x2 end if ! end program quadratic