Given the coefficients (constants) of a quadratic equation , i.e. **a, b, and c**; the task is to check whether roots of the equation represented by these constants are numerically equal but opposite in sign or not.

**Examples:**

Input:a = 2, b = 0, c = -1

Output:Yes

Explanation:

The given quadratic equation is

Its roots are (1, -1) which are numerically equal but opposite in sign

Input:a = 1, b = -5, c = 6

Output:No

Explanation:

The given quadratic equation is

Its roots are (2, 3) which are not numerically equal and opposite in sign

**Approach:**

To check whether roots are numerically equal but opposite in sign or not:

Quadratic Equation:

Let the roots be and

Sum of roots = =

Since roots are opposite in sign only, therforeTherefore,

, i.e, coefficient of x is 0.

Hence we have to only check if b is 0 or not, for the roots to be numerically equal but opposite in sign.

Below is the implementation of the above approach:

## C++

`// C++ program to check if roots ` `// of a Quadratic Equation are ` `// numerically equal but opposite ` `// in sign or not ` ` ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// Function to find the required answer ` `void` `checkSolution(` `int` `a, ` `int` `b, ` `int` `c) ` `{ ` ` ` `if` `(b == 0) ` ` ` `cout << ` `"Yes"` `; ` ` ` `else` ` ` `cout << ` `"No"` `; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `a = 2, b = 0, c = 2; ` ` ` ` ` `checkSolution(a, b, c); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to check if roots ` `// of a Quadratic Equation are ` `// numerically equal but opposite ` `// in sign or not ` `import` `java.util.*; ` `class` `GFG{ ` ` ` `// Function to find the required answer ` `static` `void` `checkSolution(` `int` `a, ` `int` `b, ` `int` `c) ` `{ ` ` ` `if` `(b == ` `0` `) ` ` ` `System.out.print(` `"Yes"` `); ` ` ` `else` ` ` `System.out.print(` `"No"` `); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String args[]) ` `{ ` ` ` `int` `a = ` `2` `, b = ` `0` `, c = ` `2` `; ` ` ` ` ` `checkSolution(a, b, c); ` `} ` `} ` ` ` `// This code is contributed by Akanksha_Rai ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to check if roots ` `# of a quadratic equation are ` `# numerically equal but opposite ` `# in sign or not ` ` ` `# Function to find the required answer ` `def` `checkSolution(a, b, c): ` ` ` ` ` `if` `b ` `=` `=` `0` `: ` ` ` `print` `(` `"Yes"` `) ` ` ` `else` `: ` ` ` `print` `(` `"No"` `) ` ` ` `# Driver code ` `a ` `=` `2` `b ` `=` `0` `c ` `=` `2` ` ` `checkSolution(a, b, c) ` ` ` `# This code is contributed by divyamohan123 ` |

*chevron_right*

*filter_none*

## C#

`// C# program to check if roots ` `// of a Quadratic Equation are ` `// numerically equal but opposite ` `// in sign or not ` `using` `System; ` `class` `GFG{ ` ` ` `// Function to find the required answer ` `static` `void` `checkSolution(` `int` `a, ` `int` `b, ` `int` `c) ` `{ ` ` ` `if` `(b == 0) ` ` ` `Console.Write(` `"Yes"` `); ` ` ` `else` ` ` `Console.Write(` `"No"` `); ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main() ` `{ ` ` ` `int` `a = 2, b = 0, c = 2; ` ` ` ` ` `checkSolution(a, b, c); ` `} ` `} ` ` ` `// This code is contributed by Akanksha_Rai ` |

*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 reciprocal of each other or not
- Roots of the quadratic equation when a + b + c = 0 without using Shridharacharya formula
- Find the quadratic equation from the given roots
- Boundary Value Analysis : Nature of Roots of a Quadratic equation
- Program to find the Roots of Quadratic equation
- Find if two given Quadratic equations have common roots or not
- 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
- Program to find number of solutions in Quadratic Equation
- 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
- Maximum score assigned to a subsequence of numerically consecutive and distinct array elements
- Time until distance gets equal to X between two objects moving in opposite direction
- Count natural numbers whose factorials are divisible by x but not y
- Find permutation of n which is divisible by 3 but not divisible by 6
- Count numbers in range 1 to N which are divisible by X but not by Y
- Position of a person diametrically opposite on a circle
- Exterior angle of a cyclic quadrilateral when the opposite interior angle is given
- Find two vertices of an isosceles triangle in which there is rectangle with opposite corners (0, 0) and (X, Y)

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.