Question

The roots of the quadratic equation ax2 + bx + c = 0, a following formula: 0 are given by the In this formula, the term i2 - 4ac is called the discriminant. If b4ac 0 then the equation has a single (repeated) root. If -4ac > 0, th equation complex roots. Write a program that prompts the user to input the value of a (the coefficient of ), b (the coefficient of x), and c (the n has two real roots. If4aco, the equation has two t term) and outputs the type of roots of the equation. Further- more, if b0, the program should output the roots of the quadratic equation. (Hint: Use the function pow from the header file cmath to calculate the square root. tion pow is used.)
1 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <cmath>//to use sqrt function
using namespace std;

int main()
{

float a, b, c, x1, x2, D, Real_Part, Imaginary_Part;
//declaration of variables
cout << "Enter coefficients a, b and c: ";

//cin is used to read the values of coefficients of the quardratic equation   
cin >> a >> b >> c;
// calculating Discriminant
D = b*b - 4*a*c;
  
  
if (D > 0)
// means roots exist and they are different
{
x1 = (-b + sqrt(D)) / (2*a);
x2 = (-b - sqrt(D)) / (2*a);
cout << "Roots are real and different." << endl;
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << endl;
}
  
//means roots exit and they are same   
else if (D == 0)
{
cout << "Roots are real and same." << endl;
x1 = (-b + sqrt(D)) / (2*a);
cout << "x1 = x2 =" << x1 << endl;
}
//if Discriminant is less than zero then roots will be Imaginary
else
{
Real_Part = -b/(2*a);
//to calculate imaginary part for each root
Imaginary_Part =sqrt(-D)/(2*a);
  
cout << "Roots are complex and different." << endl;
cout << "x1 = " << Real_Part << "+" << Imaginary_Part << "i" << endl;
cout << "x2 = " << Real_Part << "-" << Imaginary_Part << "i" << endl;
}

return 0;
}

Add a comment
Know the answer?
Add Answer to:
The roots of the quadratic equation ax2 + bx + c = 0, a following formula:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ The roots of the quadratic equation ax² + bx + c = 0, a ≠...

    C++ The roots of the quadratic equation ax² + bx + c = 0, a ≠ 0 are given by the following formula: In this formula, the term b² - 4ac is called the discriminant. If b² - 4ac = 0, then the equation has a single (repeated) root. If b² - 4ac > 0, the equation has two real roots. If b² - 4ac < 0, the equation has two complex roots. Instructions Write a program that prompts the...

  • In Python. The two roots of a quadratic equation ax^2 + bx + c = 0...

    In Python. The two roots of a quadratic equation ax^2 + bx + c = 0 can be obtained using the following formula: r1 = (-b + sqrt(b^2 - 4ac) / (2a) and r2 = (-b - sqrt(b^2 - 4ac) / (2a) b^2 - 4ac is called the discriminant of the quadratic equation. If it is positive, the equation has two real roots. If it is zero, the equation has one root. If it is negative, the equation has no...

  • The two roots of the quadratic equation ax2 + bx + c = 0 can be...

    The two roots of the quadratic equation ax2 + bx + c = 0 can be found using the quadratic formula as -b+ v62 – 4ac . -b-v6² – 4ac 1 X1 = - and x2 = 2a 2a When b2 – 4ac < 0 this yields two complex roots - -b V4ac – 62 -b Vac – 6² x1 = = +. . 2a 2a i. and x2 = . za 2al Using the quadratic formula the roots of...

  • This is in python language Algebra: solve quadratic equations) The two roots of a quadratic equation,...

    This is in python language Algebra: solve quadratic equations) The two roots of a quadratic equation, for example, 0, can be obtained using the following fomula: b 4ac is called the discriminant of the quadratic equation. If it is positive, the equation has two real roots. If it is zero, the equation has one root. If it is negative, the equation has no real roots. Write a program that prompts the user to enter values for a, b, and cand...

  • Use Python Programming. Design a class named Quadratic Equation for a quadratic equation ax + bx+c...

    Use Python Programming. Design a class named Quadratic Equation for a quadratic equation ax + bx+c 0. The class contains: • The data fields a, b, and c that represent three coefficients. . An initializer for the arguments for a, b, and c. • Three getter methods for a, b, and c. • A method named get Discriminant() that returns the discriminant, which is b- 4ac The methods named getRoot 1() and getRoot 2() for returning the two roots of...

  • A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the...

    A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the above quadratic equation is computed using the following formula, root1 = (-b + sqrt(D))/ 2a root2 = (-b - sqrt(D))/2a Where D is the discriminant of the quadratic equation and is computed as, D = b^2 - 4ac Given the value of D, the roots of a quadratic equation can be categorized as follows, D > 0 : Two distinct real roots D =...

  • reword m the program into a design document diregard the m Write a C++ program that...

    reword m the program into a design document diregard the m Write a C++ program that solves a quadratic equation to find its roots. The roots of a quadratic equation ax2 + bx + c = 0 (where a is not zero) are given by the formula -b + b2 - 4ac 2a The value of the discriminant b2 - 4ac determines the nature of roots. If the value of the discriminant is zero, then the equation has a single...

  • Java Programming Question 4 (10 points): Solutions for a quadratic equation ax(squared)+bx+c= 0. where a does...

    Java Programming Question 4 (10 points): Solutions for a quadratic equation ax(squared)+bx+c= 0. where a does not equal zero are as follows. r1=( −b+√b(squared)−4ac)/2a r2=(−b−√b(squared)−4ac)/2a if b(squared)−4ac <0, equation doesn’t have real roots. If it is 0 there is one root(r1=r2). Write a Java program to read a,b and c from keyboard and find the roots, if they exist. Note: You need to have a method that takes 3 real values as arguments

  • Help with MATLAB. i did like input('enter the coefficients of a quadratic equation "Ax2 + Bx...

    Help with MATLAB. i did like input('enter the coefficients of a quadratic equation "Ax2 + Bx + C = 0"') fx=(-B+sqrt(B^2+4*A*C))/(2*A); i just dont know how i can ask the user to input three (A,B,C)? thanks! EXERCISE 6 Ask user to enter the coefficients of a quadratic equation, Ax² + Bx + C = 0, i.e. A, B, and C, and calculate the roots of the equation using the quadratic formula, ., --B+VB? - 4AC 2A

  • CSC 211 - Lab-2 Write a C++ program to find the roots of a quadratic equation...

    CSC 211 - Lab-2 Write a C++ program to find the roots of a quadratic equation ax +bx+c=0. The roots are given by the formula, x=-b I56²-4ac 2a x = -b+ √b²-4ac 2. x2 = -b-√6²-4ac 2a Instructions: 1. Type, compile, and run the program in an online C++ compiler. 2. Open a word document and copy the following items onto it: a. The source code b. Screenshot of your program's result 3. Save the word document as lastnameFirstname_Lab2.docx (for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT