Quadratic Equation
An equation in the form of Ax^2 +Bx +C is a quadratic equation, where the value of the variables A, B, and C are constant and x is an unknown variable which we have to find through the Python program. The value of the variable A won't be equal to zero for the quadratic equation. If the value of A is zero then the equation will be linear.
Here, we are assuming a quadratic equation x^2-7x+12=0 which roots are 4 and -3.
Algorithm to solve this problem
- We store the value of variables A, B and C which is given by the user and we will use the mathematical approach to solve this.
- Here, we find the value of ((B*B)-4*A*C) and store in a variable d.
- If the value of the variable d is negative then the value of x will be imaginary numbers and print the roots of the equation is imaginary.
- If the value of the variable is positive then x will be real.
- Since the equation is quadratic, so it has two roots which are x1
and
x2
.
x1=(-B+((B*B)-4*A*C) **0.5)/2*A
x2=(-B-((B*B)-4*A*C) **0.5)/2*A
- When we will find the value of roots of the equation from the above, it may be decimal or integer but we want the answer in an integer that's why we will take math.floor() of the value of the variable x.
Python program to find the root of the quadratic equation
Output
need an explanation for this answer? contact us directly to get an explanation for this answer