Given three integers a, b and c such that a + b + c = 0. The task is to find the roots of a quadratic equation ax2 + bx + c = 0.
Input: a = 1, b = 2, c = -3
Output: 1, -3
Input: a = -5, b = 3, c = 2
Output: 1, -2.5
Approach: When a + b + c = 0 then the roots of the equation ax2 + bx + c = 0 are always 1 and c / a.
Take a = 3, b = 2 and c = -5 such that a + b + c = 0
Now, the equation will be 3x2 + 2x – 5 = 0
Solving for x,
3x2 + 5x – 3x – 5 = 0
x * (3x + 5) -1 * (3x + 5) = 0
(x – 1) * (3x + 5) = 0
x = 1, x = (-5 / 3) = (c / a)
Below is the implementation of the above approach:
Time Complexity: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find the quadratic equation from the given roots
- Boundary Value Analysis : Nature of Roots of a Quadratic equation
- Check if roots of a Quadratic Equation are numerically equal but opposite in sign or not
- Check if roots of a Quadratic Equation are reciprocal of each other or not
- Program to find the Roots of Quadratic equation
- Find if two given Quadratic equations have common roots or not
- Absolute difference between sum and product of roots of a quartic equation
- Form the Cubic equation from the given roots
- Find the integral roots of a given Cubic equation
- Program to find number of solutions in Quadratic Equation
- Check whether one root of the Quadratic Equation is twice of other or not
- Least root of given quadratic equation for value greater than equal to K
- Print first n Fibonacci Numbers using direct formula
- Program to implement Inverse Interpolation using Lagrange Formula
- Roots of Unity
- Bakhshali Approximation for computing square roots
- Seeds (Or Seed Roots) of a number
- Minimize the sum of roots of a given polynomial
- Find the number of primitive roots modulo prime
- Maximum and Minimum value of a quadratic function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.