# Find the quadratic equation from the given roots

Given the roots of a quadratic equation **A** and **B**, the task is to find the equation.

**Note**: The given roots are integral.

**Examples:**

Input:A = 2, B = 3

Output:x^2 – (5x) + (6) = 0

x^{2}– 5x + 6 = 0

x^{2}-3x -2x + 6 = 0

x(x – 3) – 2(x – 3) = 0

(x – 3) (x – 2) = 0

x = 2, 3

Input:A = 5, B = 10

Output:x^2 – (15x) + (50) = 0

**Approach:** If the roots of a quadratic equation **ax ^{2} + bx + c = 0** are

**A**and

**B**then it known that

**A + B = – b * a**and

**A * B = c * a**.

Now, ax

^{2}+ bx + c = 0 can be written as

x

^{2}+ (b / a)x + (c / a) = 0 (Since, a != 0)

x

^{2}– (A + B)x + (A * B) = 0, [Since, A + B = -b * a and A * B = c * a]

i.e.

**x**

^{2}– (Sum of the roots)x + Product of the roots = 0Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find the quadratic ` `// equation whose roots are a and b ` `void` `findEquation(` `int` `a, ` `int` `b) ` `{ ` ` ` `int` `sum = (a + b); ` ` ` `int` `product = (a * b); ` ` ` `cout << ` `"x^2 - ("` `<< sum << ` `"x) + ("` ` ` `<< product << ` `") = 0"` `; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `a = 2, b = 3; ` ` ` ` ` `findEquation(a, b); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the above approach ` `class` `GFG ` `{ ` ` ` ` ` `// Function to find the quadratic ` ` ` `// equation whose roots are a and b ` ` ` `static` `void` `findEquation(` `int` `a, ` `int` `b) ` ` ` `{ ` ` ` `int` `sum = (a + b); ` ` ` `int` `product = (a * b); ` ` ` `System.out.println(` `"x^2 - ("` `+ sum + ` ` ` `"x) + ("` `+ product + ` `") = 0"` `); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String args[]) ` ` ` `{ ` ` ` `int` `a = ` `2` `, b = ` `3` `; ` ` ` ` ` `findEquation(a, b); ` ` ` `} ` `} ` ` ` `// This code is contributed by AnkitRai01 ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function to find the quadratic ` `# equation whose roots are a and b ` `def` `findEquation(a, b): ` ` ` `summ ` `=` `(a ` `+` `b) ` ` ` `product ` `=` `(a ` `*` `b) ` ` ` `print` `(` `"x^2 - ("` `, summ, ` ` ` `"x) + ("` `, product, ` `") = 0"` `) ` ` ` `# Driver code ` `a ` `=` `2` `b ` `=` `3` ` ` `findEquation(a, b) ` ` ` `# This code is contributed by Mohit Kumar ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the above approach ` `using` `System; ` `class` `GFG ` `{ ` ` ` ` ` `// Function to find the quadratic ` ` ` `// equation whose roots are a and b ` ` ` `static` `void` `findEquation(` `int` `a, ` `int` `b) ` ` ` `{ ` ` ` `int` `sum = (a + b); ` ` ` `int` `product = (a * b); ` ` ` `Console.WriteLine(` `"x^2 - ("` `+ sum + ` ` ` `"x) + ("` `+ product + ` `") = 0"` `); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `int` `a = 2, b = 3; ` ` ` ` ` `findEquation(a, b); ` ` ` `} ` `} ` ` ` `// This code is contributed by CodeMech. ` |

*chevron_right*

*filter_none*

**Output:**

x^2 - (5x) + (6) = 0

## Recommended Posts:

- Program to find the Roots of Quadratic equation
- Roots of the quadratic equation when a + b + c = 0 without using Shridharacharya formula
- Program to find number of solutions in Quadratic Equation
- Absolute difference between sum and product of roots of a quartic equation
- Find the number of primitive roots modulo prime
- Find the missing value from the given equation a + b = c
- Find the number of solutions to the given equation
- Find number of solutions of a linear equation of n variables
- Roots of Unity
- Sum of first N terms of Quadratic Sequence 3 + 7 + 13 + ...
- Maximum and Minimum value of a quadratic function
- Seeds (Or Seed Roots) of a number
- Bakhshali Approximation for computing square roots
- Number of solutions for the equation x + y + z <= n
- Equation of circle from centre and radius

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.