Modify the given Program so that it will calculate all possible roots of quadratic equation.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float a, b, c, x1, x2, determinant, realPart, imaginaryPart;
cout << "Enter coefficients a, b and c: ";
cin >> a >> b >> c;
determinant = b*b - 4*a*c;
if (determinant > 0)
{
x1 = (-b + sqrt(determinant)) / (2*a);
x2 = (-b - sqrt(determinant)) / (2*a);
cout << "Roots are real and different." << endl;
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << endl;
}
else if (determinant == 0)
{
cout << "Roots are real and same." << endl;
x1 = (-b + sqrt(determinant)) / (2*a);
cout << "x1 = x2 =" << x1 << endl;
}
else
{
realPart = -b/(2*a);
imaginaryPart =sqrt(-determinant)/(2*a);
cout << "Roots are complex and different." <<
endl;
cout << "x1 = " << realPart << "+" <<
imaginaryPart << "i" << endl;
cout << "x2 = " << realPart << "-" <<
imaginaryPart << "i" << endl;
}
return 0;
}
Modify the given Program so that it will calculate all possible roots of quadratic equation.
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...
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...
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...
O EQUATIONS AND INEQUALITIES Writing a quadratic equation given the roots and the leading... Student v Write the quadratic equation whose roots are -3 and 2, and whose leading coefficient is 2. (Use the letter x to represent the variable.) х $ ? Aa Explanation Check 2020 McGraw-Hill Education. All Rights Reserved. Terms of Use Privacy Accessibility
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...
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...
Use C++, visual studio format. Please Write a program to solve the quadratic equation and find only the real and equal roots. the program should test for three types of roots tell the users the roots type and then calculate the real roots. the user enters the values of a ,b and c. you calculate r1 and r2. c
Write a C++ program to compute both roots of the quadratic equation when the user provides the three coefficients A, B, and C. Specifically, A. Display “Your Name” B. Display “Project_2 Problem_1” C. Display “This program computes both roots of a quadratic equation” D. Display “given the coefficients A, B, and C” E. Real_1 = 0 F. Real_2 = 0 G. Imag = 0 H. D = 0 I. DD =0 J. Flag = ‘Y’ K. DO a. A =...
Question 2 (15 points) (a) Find all the roots of the quadratic equation 2.2 - 2.2 +3, including complex roots. (b) Convert the number u = -27i into polar form, namely in the form u = rei where r = \ul and (c) Find all complex numbers z such that 2+ = -27i, and express all solutions in Cartesian form. argu.
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...