Header Ads Widget

Roots of quadratic equation in python

Here in this post we will write a code to find out roots of the quadratic equations . So first we have to know the formula which we are going to use in this program . For finding the roots of a quadratic equation we use the formula:-

x=b±b24ac2a

is used to solve quadratic equation where a ≠ 0 .

When  there is one real root.

 When  there are two real roots.

 When 
 there are two complex roots.


Code:-
import cmath
a=1
b=5
c=6
dis = (b**2) - (4 * a*c)
ans1 = (-b-cmath.sqrt(dis))/(2 * a)
ans2 = (-b + cmath.sqrt(dis))/(2 * a)
print("The roots are")
print(ans1,ans2)

Output:-
The roots are
(-3+0j) (-2+0j)





Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-








Post a Comment

0 Comments