program quad2 implicit none real a,b,c,D,x1,x2,x1real,x1imag,x2real,x2imag write(*,'(a,$)') 'input coefficients a, b, c: ' read(*,*) a,b,c D = b*b - 4.0*a*c if(D .gt. 0.0)then if ( b .ge. 0.0 ) then x2 = ( -b - sqrt( D ) ) / ( 2.0*a ) x1 = c / a / x2 else if ( b .lt. 0.0 ) then x1 = ( -b + sqrt( D ) ) / ( 2.0*a ) x2 = c / a / x1 end if write(*,'(2e16.8)') x1,x2 else if(D .eq. 0.0)then write(*,'(e15.8)') -b / (2.0*a) else if(D .lt. 0.0)then x1real = -b / (2.0*a) x2real = x1real x1imag = sqrt( -D ) / (2.0*a) x2imag = -x1imag write(*,'(2e15.8,a)') x1real,x1imag,'i' write(*,'(2e15.8,a)') x2real,x2imag,'i' end if end program quad2