Bishwajit123

Quadratic equation

Jan 25th, 2019
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. a=int(input("Enter a: "))
  2. b=int(input("Enter b: "))
  3. c=int(input("Enter c: "))
  4.  
  5.  
  6. d = b**2-4*a*c
  7. x1 = (-b + (d**0.5))/2*a
  8. x2 = (-b - (d**0.5))/2*a
  9.  
  10.  
  11. #for complex
  12. c1 = (-b/2*a)
  13. c2 = ((-d)**0.5)/(2*a)
  14.  
  15.  
  16. #complex----- output a+ib and a-ib formated by (c1+ic2),(c1-ic2)
  17. if(d >= 0):
  18.         print("Roots are : ",x1,"and",x2)
  19. else:
  20.         print("Roots are : (",c1,"+ i",c2,")    (",c1,"- i",c2,")")
Add Comment
Please, Sign In to add comment