22.1k views
1 vote
Write a program that will solve a quadratic equation: ax2 + bx + c = 0. The program must ask the user to enter the values for a, b and c. It should then determine the discriminant of the parabola and based on the discriminant it should display the real roots: Discriminant = b2 - 4ac > 0 means there will be two distinct real roots. Discriminant = b2 - 4ac = 0 means there will be only one real root. Discriminant = b2 - 4ac < 0 means there will be no real roots. Use the if - then else structure in your program to decide the outcome of the program. User must then use the quadratic equation to solve for x: = − ± √ −

User Dols
by
4.1k points

1 Answer

3 votes

Answer:

x= -b ±√b²- 4ac/2a

Explanation:

ax2 + bx + c = 0

Dividing the quadratic equation by a gives

x2 + b/ax + c/a = 0

x2 + b/ax = - c/a

Applying the square formula

(x)^2 + 2(x) (b/2a) + (b/2a)^2= + (b/2a)^2- c/a

(x+b/2a)^2= b²/4a² - c/a

(x+b/2a)^2= b²/4a² - 4ac/4a²

(x+b/2a)^2= b²- 4ac/4a²

Taking square root of both sides gives

(x+b/2a)= ±√b²- 4ac/2a

x= -b/2a±√b²- 4ac/2a

x= -b ±√b²- 4ac/2a

This is called the quadratic formula and it can solve the value for x for the given value of a, b and c for the quadratic equation.

From this it is concluded that

Discriminant = b2 - 4ac > 0 means there will be two distinct real roots. Discriminant = b2 - 4ac = 0 means there will be only one real root. Discriminant = b2 - 4ac < 0 means there will be no real roots.

This is because a square root of a value greater than 0 is possible and gives two values for roots of x.

The square root of a value less than 0 gives a negative number and therefore the roots are an imaginary number.

The square root of a value greater equal to 0 gives a zero leaving behind only one real root.

User Bart Verkoeijen
by
4.5k points