program qes

  implicit none
  integer :: a, b, c, D
  real :: real_part, imag_part
  
  write(*,*) "Enter the values for a, b and c"
  read(*,*) a, b, c
  if (a /= 0) then
  ! calculate discriminant
    D = b*b - 4*a*c
    if (d == 0) then           ! one root
      print*, "Root is ", -b/(2.0*a)
    elseif (d > 0) then        ! real roots
      print*, "Roots are", (-b+sqrt(real(d)))/(2.0*a), &
              "and",       (-b-sqrt(real(d)))/(2.0*a)
    else                       ! complex roots
      real_part = -b/(2.0*a)
    ! D < 0 so must take SQRT of -D
      imag_part = (sqrt(real(-d))/(2.0*a))
      print*, "1st root", real_part,"+",imag_part,"i"
      print*, "2nd root", real_part,"-",imag_part,"i"
    endif
  else                         ! a == 0
    print*, "Not a quadratic equation"
  endif
  
end program qes