Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function that takes the coefficients of the quadratic equation and retur

ID: 3697065 • Letter: W

Question

Write a function that takes the coefficients of the quadratic equation and returns the real roots if exist.

Write a function that takes the coefficients of the quadratic equation and returns the real roots if exist. 3. Hint: a quadratic equation is in the form of ax2+ bx + c = 0 The roots can be calculated as 2a to the quadratic equation is given by the quadratic formula: The expression inside the square root is called discriminant and is denoted by : The quadratic formula with discriminant notation: x1.2 = 20 This expression is important because it can tell us about the solution: when >0, there are 2 real roots x1s(-b+VA)/(2a) and x2=(-b-VA)/(2a). when =0, there is one root x1EX2:-b/(2a). when

Explanation / Answer

program for function that takes the coefficients of the quadratic equation and returns the real roots if exist:

in java:

import java.util.Scanner;

class Quadratic  {

     

    public static void main(String[] args){

        Scanner scanner = new Scanner(System.in);

        System.out.println("Enter the values of a, b and c");

        double a = scanner.nextDouble();

        double b = scanner.nextDouble();

        double c = scanner.nextDouble();

        double r1 = 0;

        double r2 = 0;

double discriminant = b * b - 4 * a * c;

        if (discriminant > 0){

            r1 = (-b + Math.sqrt(discriminant)) / (2 * a);

            r2 = (-b - Math.sqrt(discriminant)) / (2 * a);

System.out.println("The equation has two real roots " + r1 + " and " + r2);

        }

if (discriminant == 0){

            System.out.println("The equation has one root " +r1);

r1 = -b / (2 * a);

            r2 = -b / (2 * a);

} if (discriminant < 0){

            System.out.println("The equation has no real root");

}

}

}

note:In the above program you have to pass the 3 parameters as inputs at runtime .

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote