Given values **a1**, **b1** and **c1** of first Quadratic equations and values **a2**, **b2** and **c2** of second Quadratic equations , the task is to find whether both quadratic equations have common roots or not.

**Examples:**

Input:a1 = 1, b1 = -5, c1 = 6, a2 = 2, b2 = -10, c2 = 12

Output:Yes

Explanation:

Roots of both quadratic equations are (2, 3)

Input:a1 = 1, b1 = -5, c1 = 6, a2 = 1, b2 = -9, c2 = 20

Output:No

Explanation:

Roots of first quadratic equations are (2, 3), and Roots of second quadratic equations are (4, 5)

Therefore, both quadratic equations have differnt roots.

**Approach:**

Let the two quadratic equations are and

- Let us assume the given condition to be true, i.e. both the equations have common roots, say and
- As we know that

and

where a, b, c represents the quadratic equation - Therefore,

For 1st quadratic equation:

Similarly, for 2nd quadratic equation:

- Now since both the roots are common,

Therfore, from above equations

- Also,

- Combining the above equations:

which is the required

**condition for both roots to be common**of the two quadratic equations.

**Programs:**

## C++

`// C++ Program to Find if two given ` `// Quadratic equations have ` `// common roots or not ` ` ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// function to check if 2 quadratic ` `// equations have common roots or not. ` `bool` `checkSolution(` `float` `a1, ` `float` `b1, ` ` ` `float` `c1, ` `float` `a2, ` ` ` `float` `b2, ` `float` `c2) ` `{ ` ` ` `return` `(a1 / a2) == (b1 / b2) ` ` ` `&& (b1 / b2) == (c1 / c2); ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `float` `a1 = 1, b1 = -5, c1 = 6; ` ` ` `float` `a2 = 2, b2 = -10, c2 = 12; ` ` ` `if` `(checkSolution(a1, b1, c1, a2, b2, c2)) ` ` ` `cout << ` `"Yes"` `; ` ` ` `else` ` ` `cout << ` `"No"` `; ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java Program to Find if two given ` `// quadratic equations have common ` `// roots or not ` `class` `GFG { ` ` ` `// Function to check if 2 quadratic ` `// equations have common roots or not. ` `static` `boolean` `checkSolution(` `float` `a1, ` `float` `b1, ` ` ` `float` `c1, ` `float` `a2, ` ` ` `float` `b2, ` `float` `c2) ` `{ ` ` ` `return` `((a1 / a2) == (b1 / b2) && ` ` ` `(b1 / b2) == (c1 / c2)); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main (String[] args) ` `{ ` ` ` `float` `a1 = ` `1` `, b1 = -` `5` `, c1 = ` `6` `; ` ` ` `float` `a2 = ` `2` `, b2 = -` `10` `, c2 = ` `12` `; ` ` ` ` ` `if` `(checkSolution(a1, b1, c1, a2, b2, c2)) ` ` ` `System.out.println(` `"Yes"` `); ` ` ` `else` ` ` `System.out.println(` `"No"` `); ` `} ` `} ` ` ` `// This code is contributed by AnkitRai01 ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find if two given ` `# quadratic equations have common ` `# roots or not ` ` ` `# Function to check if 2 quadratic ` `# equations have common roots or not. ` `def` `checkSolution(a1, b1, c1, a2, b2, c2): ` ` ` ` ` `return` `((a1 ` `/` `a2) ` `=` `=` `(b1 ` `/` `b2) ` `and` ` ` `(b1 ` `/` `b2) ` `=` `=` `(c1 ` `/` `c2)) ` ` ` `# Driver code ` `a1, b1, c1 ` `=` `1` `, ` `-` `5` `, ` `6` `a2, b2, c2 ` `=` `2` `, ` `-` `10` `, ` `12` ` ` `if` `(checkSolution(a1, b1, c1, a2, b2, c2)): ` ` ` `print` `(` `"Yes"` `) ` `else` `: ` ` ` `print` `(` `"No"` `) ` ` ` `# This code is contributed by divyamohan123 ` |

*chevron_right*

*filter_none*

## C#

`// C# Program to Find if two given ` `// quadratic equations have common ` `// roots or not ` `using` `System; ` `class` `GFG{ ` ` ` `// Function to check if 2 quadratic ` `// equations have common roots or not. ` `static` `bool` `checkSolution(` `float` `a1, ` `float` `b1, ` ` ` `float` `c1, ` `float` `a2, ` ` ` `float` `b2, ` `float` `c2) ` `{ ` ` ` `return` `((a1 / a2) == (b1 / b2) && ` ` ` `(b1 / b2) == (c1 / c2)); ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main (` `string` `[] args) ` `{ ` ` ` `float` `a1 = 1, b1 = -5, c1 = 6; ` ` ` `float` `a2 = 2, b2 = -10, c2 = 12; ` ` ` ` ` `if` `(checkSolution(a1, b1, c1, a2, b2, c2)) ` ` ` `Console.WriteLine(` `"Yes"` `); ` ` ` `else` ` ` `Console.WriteLine(` `"No"` `); ` `} ` `} ` ` ` `// This code is contributed by AnkitRai01 ` |

*chevron_right*

*filter_none*

**Output:**

Yes

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:

- 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
- Find the quadratic equation from the given roots
- Program to find the Roots of Quadratic equation
- Roots of the quadratic equation when a + b + c = 0 without using Shridharacharya formula
- Boundary Value Analysis : Nature of Roots of a Quadratic equation
- Check whether one root of the Quadratic Equation is twice of other or not
- Maximize partitions such that no two substrings have any common character
- Find the integral roots of a given Cubic equation
- Find the repeating and the missing number using two equations
- Number of triangles formed by joining vertices of n-sided polygon with two common sides and no common sides
- Find 'N' number of solutions with the given inequality equations
- Find the values of X and Y in the Given Equations
- Find n positive integers that satisfy the given equations
- Find the number of primitive roots modulo prime
- Program to find number of solutions in Quadratic Equation
- Form the Cubic equation from the given roots
- Least root of given quadratic equation for value greater than equal to K
- Count divisors of n that have at-least one digit common with n
- Maximum length subsequence such that adjacent elements in the subsequence have a common factor

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.