program edsd
  implicit none
  logical :: delta_positif=.true.
  real :: a,b,c,delta,x1,x2
  complex :: z1,z2
  character :: choix
  integer :: nbre_equations
  nbre_equations=0; choix='c'
  do
     print*,"Continuer (c) ou Quitter (q) ?"; read*,choix
     select case (choix)
     case ('c')
        print*,"Coefficients ('real') a,b,c ?"; read*,a,b,c      
        delta=b**2-4*a*c
        if (abs(delta)<epsilon(b)*abs(b)*2) then
           x1=-b/2/a
           x2=x1
        else if (delta>0) then
           x1=-(b+sign(sqrt(delta),b))/2/a
           x2=c/a/x1
        else ! (delta<0)
           z1=cmplx(-b, sqrt(-delta))/2/a
           z2=conjg(z1)
           delta_positif=.false.
        end if
        if (delta_positif) then
           print*,"discriminant positif, x1 et x2 :"
           print*,x1,x2
        else
           print*,"discriminant negatif, z1 et z2 :"
           print*,z1,z2
        end if
        nbre_equations=nbre_equations+1
     case ('q')
        exit
     case default
        print*,"Merci de repondre par 'c' ou 'q'."
        continue
     end select
  end do
  print*,"Nous avons resolu ",nbre_equations," equations." 
end program
