Given three integers **a**, **b** and **c** such that **a + b + c = 0**. The task is to find the roots of a quadratic equation **ax ^{2} + bx + c = 0**.

**Examples:**

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 **ax ^{2} + bx + c = 0** are always

**1**and

**c / a**.

For example,

Take a = 3, b = 2 and c = -5 such that a + b + c = 0

Now, the equation will be 3x^{2}+ 2x – 5 = 0

Solving for x,

3x^{2}+ 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:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to print the roots of the ` `// quadratic equation when a + b + c = 0 ` `void` `printRoots(` `long` `a, ` `long` `b, ` `long` `c) ` `{ ` ` ` `cout << 1 << ` `", "` `<< c / (a * 1.0); ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `long` `a = 2; ` ` ` `long` `b = 3; ` ` ` `long` `c = -5; ` ` ` `printRoots(a, b, c); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GFG ` `{ ` ` ` ` ` `// Function to print the roots of the ` ` ` `// quadratic equation when a + b + c = 0 ` ` ` `static` `void` `printRoots(` `long` `a, ` `long` `b, ` `long` `c) ` ` ` `{ ` ` ` `System.out.println(` `1` `+ ` `", "` `+ c / (a * ` `1.0` `)); ` ` ` `} ` ` ` ` ` `// Driver Code ` ` ` `public` `static` `void` `main (String[] args) ` ` ` `{ ` ` ` `long` `a = ` `2` `; ` ` ` `long` `b = ` `3` `; ` ` ` `long` `c = -` `5` `; ` ` ` `printRoots(a, b, c); ` ` ` `} ` `} ` ` ` `// This code is contributed by ` `// sanjeev2552 ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function to print the roots of the ` `# quadratic equation when a + b + c = 0 ` `def` `printRoots(a, b, c): ` ` ` `print` `(` `1` `, ` `","` `, c ` `/` `(a ` `*` `1.0` `)) ` ` ` `# Driver code ` `a ` `=` `2` `b ` `=` `3` `c ` `=` `-` `5` `printRoots(a, b, c) ` ` ` `# This code is contributed by Mohit Kumar ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to print the roots of the ` `// quadratic equation when a + b + c = 0 ` `static` `void` `printRoots(` `long` `a, ` `long` `b, ` `long` `c) ` `{ ` ` ` `Console.WriteLine(` `"1, "` `+ c / (a * 1.0)); ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main() ` `{ ` ` ` `long` `a = 2; ` ` ` `long` `b = 3; ` ` ` `long` `c = -5; ` ` ` `printRoots(a, b, c); ` `} ` `} ` ` ` `// This code is contributed by Nidhi ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of the approach ` ` ` `// Function to print the roots of the ` `// quadratic equation when a + b + c = 0 ` `function` `printRoots(` `$a` `, ` `$b` `, ` `$c` `) ` `{ ` ` ` `echo` `"1"` `; ` ` ` `echo` `", "` `; ` ` ` `echo` `$c` `/ (` `$a` `* 1.0); ` `} ` ` ` `// Driver code ` `$a` `= 2; ` `$b` `= 3; ` `$c` `= -5; ` `printRoots(` `$a` `, ` `$b` `, ` `$c` `); ` ` ` `// This code is contributed by Naman_Garg. ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

1, -2.5

**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.

## Recommended Posts:

- Find the quadratic equation from the given roots
- Check if roots of a Quadratic Equation are reciprocal of each other or not
- Program to find the Roots of Quadratic equation
- 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
- Find if two given Quadratic equations have common roots or not
- Form the Cubic equation from the given roots
- Check whether one root of the Quadratic Equation is twice of other or not
- Find the integral roots of a given Cubic equation
- Least root of given quadratic equation for value greater than equal to K
- Absolute difference between sum and product of roots of a quartic equation
- Program to find number of solutions in Quadratic Equation
- Roots of Unity
- Minimize the sum of roots of a given polynomial
- Sum of first N terms of Quadratic Sequence 3 + 7 + 13 + ...
- Program for Stirling Interpolation Formula
- Seeds (Or Seed Roots) of a number
- Maximum and Minimum value of a quadratic function
- Print first n Fibonacci Numbers using direct formula
- Newton's Divided Difference Interpolation Formula

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.