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

import java.util.Scanner; public class QuadraticRootTool * @param args public st

ID: 3742192 • Letter: I

Question

import java.util.Scanner; public class QuadraticRootTool * @param args public static void main (String [] args) Scanner input new Scanner (System.in); System.out.print("Enter a, b, c: "); double ainput.nextDouble); double binput.nextDouble); double c-input.nextDouble(); double discrim b * b-4*a*c; if (discrim 0) double r1-(-b + Math.sgrt(discrim)) / (2 a); double r2-(-b Math.sqgrt dissrim)) / (2 * a); System.out.println("The equation has two roots: " +rland " + r2): else // if(discrim0) double r--b / (2 a); System.out.println("The equation has one root: "+ r);

Explanation / Answer

Answer:

#include <iostream>

using namespace std;

int main()
{
    double a,b,c;
    cout << "Enter value of a: ";
    cin >> a;
    cout << "Enter value of b: ";
    cin >> b;

    cout << "Enter value of c : ";
    cin >> c;
    double discrim = b*b - 4 * a * c;
if(discrim < 0)
{
cout<<"The equation has no real roots");
}
else if(discrim >0)
{
   double r1 = (-b + Math.sqrt(discrim))/(2*a);
   double r2 = (-b + Math.sqrt(discrim))/(2*a);
cout<<"The equation has two roots:" <<r1 <<" and"<<r2;

}
else if(discrim ==0)
{
   double r = -b/(2*a);
   System.out.println("The equation has one root i.e "<<r;
}
    }
}