Question

Write a C++ programming code for a non-zero, discuss the roots of the quadratic equation as...

Write a C++ programming code for a non-zero, discuss the roots of the quadratic equation as follows:

a) D =0; the equation has a double solution.

     x1 = x2 = -b/2a

b) D>0; the question has two different solutions x1 and x2.

     x1= (-b-sqrt(D))/2a

     x2= (-b+sqrt(D))/2a

c) if D<0; the equation has no real solution

Homework Answers

Answer #1

#include <iostream>
#include <cmath>
using namespace std;

int main() {

double a, b, c;
double x1, x2;
double determinant;
cout << "Enter coefficients a, b and c: " <<endl;
cin >> a >> b >> c;
  
determinant = b*b - 4*a*c;
  
if (determinant == 0)
{
cout << "The equation has a double solution." << endl;
x1 = (-b ) / (2*a);
cout << "x1 = x2 =" << x1 << endl;
}

  
else if (determinant > 0) {
x1 = (-b + sqrt(determinant)) / (2*a);
x2 = (-b - sqrt(determinant)) / (2*a);
cout << " The equation has two different solutions.Roots are real and different." << endl;
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << endl;
}
  

else {
  
cout << "The equation has no real solution" << endl;
  
}

return 0;
}

Know the answer?
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
Similar Questions
The roots (solutions) to the quadratic equation ax2 +bx+c = 0 is given by the well-known...
The roots (solutions) to the quadratic equation ax2 +bx+c = 0 is given by the well-known formula x = 2a −b ± √b −4ac 2 Write a python program that takes the three coefficients a, b, and c as input, computes and displays the solutions according to the aforementioned formula. Note the ± in the numerator means there are two answers. But this will not apply if a is zero, so that condition must be checked separately; design your program...
Given r_1 and r_2 are the roots of the quadratic equation ax^2 + bx + c...
Given r_1 and r_2 are the roots of the quadratic equation ax^2 + bx + c = 0, express (b^2?4ac)/2a in terms of r_1 and r_2. Re-write the quadratic formula in terms of r_1 + r_2 and and r_1 ? r_2.
USING MATLAB Write a program called QuadProg that determines the roots of a quadratic equation. Use...
USING MATLAB Write a program called QuadProg that determines the roots of a quadratic equation. Use functions to implement each action. Zip you directory of *.m files into a single file and turn this in on BBLearn under Class Activities. QuadProg write a function called getInputs to get a single input value. write a function called findDiscriminant write a function called findDenominator write a function called findRoot which will be used for both roots write a function called displayResults displayResults...
C# programming Create a class called QuadraticEq that has a custom constructor that takes in a,...
C# programming Create a class called QuadraticEq that has a custom constructor that takes in a, b and c as the quadratic equation coefficients. Implement also the following: A readonly property double Discriminant that represents discriminant to the equation A method double[] GetRealRoots() that returns an array of the real roots of the equation; size can be 2, 1 or 0 Please pay attention to encapsulation concerns. Use your created class in the following way inside a Main method to...
Python programming Write a program that prompts the user to input the three coefficients a, b,...
Python programming Write a program that prompts the user to input the three coefficients a, b, and c of a quadratic equationax2+bx+c= 0.The program should display the solutions of this equation, in the following manner: 1. If the equation has one solution, display ONE SOLUTION:, followed by the solution, displayed with4 digits printed out after the decimal place. 2. If the equation has two real solutions, display TWO REAL SOLUTIONS:, followed by the two solutions, each displayed with4 digits printed...
Consider the following differential equation 32x 2y '' + 3 (1 − e 2x )y =...
Consider the following differential equation 32x 2y '' + 3 (1 − e 2x )y = 0 (b) Determine the indicial equation and find its roots. (c) Without solving the problem, formally write the two linearly independent solutions near x = 0. (d) What can you say about the radius of convergence of the power series in (c)? (e) Find the first three non-zero terms of the two linearly independent solutions.
The following is the mathematical model of a linear programming problem for profit: Maximize subject to...
The following is the mathematical model of a linear programming problem for profit: Maximize subject to Z = 2X1 + 3X2 4X1+9X2 ≤ 72 10X1 + 11X2 ≤ 110 17X1 + 9X2 ≤ 153 X1 , X2 ≥ 0 The constraint lines have been graphed below along with one example profit line (dashed). The decision variable X1 is used as the X axis of the graph. Use this information for questions 19 through 23. A). Which of the following gives...
Let A be a given (3 × 3) matrix, and consider the equation Ax = c,...
Let A be a given (3 × 3) matrix, and consider the equation Ax = c, with c = [1 0 − 1 ]T . Suppose that the two vectors x1 =[ 1 2 3]T and x2 =[ 3 2 1] T are solutions to the above equation. (a) Find a vector v in N (A). (b) Using the result in part (a), find another solution to the equation Ax = c. (c) With the given information, what are the...
Python Programming 1. Write the following Python expressions in mathematical notation. a. dm = m *...
Python Programming 1. Write the following Python expressions in mathematical notation. a. dm = m * (sqrt(1 + v / c) / sqrt(1 - v / c) - 1) b. volume = pi * r * r * h c. volume = 4 * pi * r ** 3 / 3 d. z = sqrt(x * x + y * y) 2. What are the values of the following expressions? In each line, assume that s = "Hello" t =...
Choose either true or false for each statement a. There is a vector [b1 b2] so...
Choose either true or false for each statement a. There is a vector [b1 b2] so that the set of solutions to 1 0 1 0 1 0 [ x1, x2 , x3,] =[b1b2] is the z-axis.   b. The homogeneous system Ax=0 has the trivial solution if and only if the system has at least one free variable. c. If x is a nontrivial solution of Ax=0, then every entry of x is nonzero. d. The equation Ax=b is homogeneous...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT