Open In App

Quadratic equation whose roots are reciprocal to the roots of given equation

Given three integers A, B, and C representing the coefficients of a quadratic equation Ax2 + Bx + C = 0, the task is to find the quadratic equation whose roots are reciprocal to the roots of the given equation.

Examples:



Input: A = 1, B = -5, C = 6 
Output: (6)x^2 +(-5)x + (1) = 0
Explanation: 
The given quadratic equation x2 – 5x + 6 = 0.
Roots of the above equation are 2, 3.
Reciprocal of these roots are 1/2, 1/3.
Therefore, the quadratic equation with these reciprocal roots is 6x2 – 5x + 1 = 0.

Input: A = 1, B = -7, C = 12
Output: (12)x^2 +(-7)x + (1) = 0



Approach: The idea is to use the concept of quadratic roots to solve the problem. Follow the steps below to solve the problem:

Below is the implementation of the above approach: 




// C++ program for the above approach
 
#include <bits/stdc++.h>
using namespace std;
 
// Function to find the quadratic
// equation having reciprocal roots
void findEquation(int A, int B, int C)
{
    // Print quadratic equation
    cout << "(" << C << ")"
         << "x^2 +(" << B << ")x + ("
         << A << ") = 0";
}
 
// Driver Code
int main()
{
    // Given coefficients
    int A = 1, B = -5, C = 6;
 
    // Function call to find the quadratic
    // equation having reciprocal roots
    findEquation(A, B, C);
 
    return 0;
}




// Java program for the above approach
class GFG{
  
// Function to find the quadratic
// equation having reciprocal roots
static void findEquation(int A, int B, int C)
{
     
    // Print quadratic equation
    System.out.print("(" + C + ")"
                "x^2 +(" + B + ")x + (" +
                           A + ") = 0");
}
 
// Driver Code
public static void main(String args[])
{
     
    // Given coefficients
    int A = 1, B = -5, C = 6;
 
    // Function call to find the quadratic
    // equation having reciprocal roots
    findEquation(A, B, C);
}
}
 
// This code is contributed by AnkThon




# Python3 program for the above approach
 
# Function to find the quadratic
# equation having reciprocal roots
def findEquation(A, B, C):
     
    # Print quadratic equation
    print("(" + str(C)  + ")" +
     "x^2 +(" + str(B) + ")x + (" +
                str(A) + ") = 0")
 
# Driver Code
if __name__ == "__main__":
     
    # Given coefficients
    A = 1
    B = -5
    C = 6
 
    # Function call to find the quadratic
    # equation having reciprocal roots
    findEquation(A, B, C)
 
# This code is contributed by AnkThon




// C# program for the above approach
using System;
using System.Collections.Generic;
 
class GFG{
  
// Function to find the quadratic
// equation having reciprocal roots
static void findEquation(int A, int B, int C)
{
    // Print quadratic equation
    Console.Write("(" + C + ")"
             "x^2 +(" + B + ")x + (" +
                        A + ") = 0");
}
 
// Driver Code
public static void Main()
{
     
    // Given coefficients
    int A = 1, B = -5, C = 6;
 
    // Function call to find the quadratic
    // equation having reciprocal roots
    findEquation(A, B, C);
}
}
 
// This code is contributed by bgangwar59




<script>
 
        // Javascript program for the above approach
 
        // Function to find the quadratic
        // equation having reciprocal roots
        function findEquation(A, B, C)
        {
            // Print quadratic equation
            document.write("(" + C + ")" +
                "x^2 +(" + B +
                ")x + (" + A + ") = 0")
 
        }
 
        // Driver Code
 
        // Given coefficients
        let A = 1, B = -5, C = 6;
 
        // Function call to find the quadratic
        // equation having reciprocal roots
        findEquation(A, B, C);
 
        // This code is contributed by Hritik
         
    </script>

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

 

Time Complexity: O(1)
Auxiliary Space: O(1)

 


Article Tags :