📜  检查二次方程的根是否在数值上相等但符号相反

📅  最后修改于: 2021-04-24 22:32:10             🧑  作者: Mango

给定二次方程的系数(常数) ax^{2} + bx + c=0  ,即a,b和c ;任务是检查由这些常数表示的方程式的根在数值上是否相等,但符号是否相反。
例子:

方法:
要检查根在数值上是否相等但符号相反:

因此,我们仅需检查b是否为0,以使根在数值上相等但符号相反。
下面是上述方法的实现:

C++
// C++ program to check if roots
// of a Quadratic Equation are
// numerically equal but opposite
// in sign or not
 
#include 
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;
}


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


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


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


Javascript


输出:
Yes