fork download
  1. program Find_root
  2. implicit none
  3. integer::a,b,c
  4. real :: x1,x2,d
  5. complex :: c1,c2
  6. read(*,*) a,b,c
  7. d=(b*b)-4*a*c
  8. if(d<0) then
  9. d =- d
  10. c1 = cmplx(-b/(2*a),sqrt(d)/(2.0*a))
  11. c2 = cmplx(-b/(2*a),-sqrt(d)/(2.0*a))
  12. print*, "x1= ", c1
  13. print*, "x2= ", c2
  14. else
  15. x1=((-b)+ sqrt(d))/(2*a)
  16. x2=((-b)- sqrt(d))/(2*a)
  17. print*, "x1= ", x1
  18. print*, "x2= ", x2
  19. end if
  20. end program Find_root
  21.  
Success #stdin #stdout 0.01s 5320KB
stdin
1 5 6
stdout
 x1=   -2.00000000    
 x2=   -3.00000000