Write a C program, to solve the quadratic equation a x2 + b x + c = 0 of given coefficients a, b and c. When running the program, it prompts for the input of coefficients a,b,c as floating numbers. After inputting three floating numbers, it computes and prints out the solutions, then prompts for another round of input. Your program will quit when getting input 0,0,0. Your program should handle four situations: (1) a=0, not a quadratic equation; (2) b2 - 4ac = 0, the equation has two equal roots; (3) b2 - 4ac < 0, the equation has complex roots; (4) b2 - 4ac > 0, the equation has distinct real roots. Your program should be robust for invalid inputs.
output:
Please enter the coefficients a,b,c:
1,2,1
The equation has two equal real roots:
-1.000000
Please enter the coefficients a,b,c:
1,2,2
The equation has two complex roots:
-1.000000+1.000000i -1.000000-1.000000i
Please enter the coefficients a,b,c:
2,6,1
The equation has two distinct real roots:
-0.177124 -2.822875
Please enter the coefficients a,b,c:
a,b,c
Invalid input
Please enter the coefficients a,b,c:
1,2
Invalid input
Please enter the coefficients a,b,c:
0,1,2
not a quadratic equation
Please enter the coefficients a,b,c:
0,0,0
Goodbye
code:
#include<stdio.h>
int main()
{
float a,b,c;
while(1)
{
printf("Please enter the coefficients a,b,c:");
int k=scanf("%f%f%f",&a,&b,&c);
fflush(stdin);
if(k!=3)
{
printf("Invalid input\n");
continue;
}
if(a==0&&b==0&&c==0)
{
printf("Goodbye\n");
break;
}
if(a==0)
{
printf("not a quadratic equation\n");
continue;
}
float x=b*b-4*a*c;
if(x==0)
{
printf("The equation has two equal real roots:\n");
printf("%f\n",-b/(2.0*a));
}
else if(x>0)
{
printf("The equation has two distinct real roots:\n");
printf("%f %f\n",(-b+sqrt(x))/(2.0*a),(-b-sqrt(x))/(2.0*a));
}
else if(x<0)
{
printf("The equation has two complex roots:\n");
printf("%f+%fi ",-b/(2.0*a),sqrt(-x)/(2.0*a));
printf("%f%fi\n",-b/(2.0*a),-sqrt(-x)/(2.0*a));
}
}
}
Write a C program, to solve the quadratic equation a x2 + b x + c...
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...
please answer this question with python.
Write a program to solve the quadratic equation ax^2 + bx + c = 0 using the standard quadratic formula x = -b plusminus Squareroot b^2 - 4ac/2a or the alternative formula x = 2c/-b Squareroot b^2 - 4ac. Your program should accept values for the coefficients a, b, and c as input and produce the two roots of the equation as output. Your program should detect when the roots are imaginary, but need...
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...
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...
(Algebra: solve quadratic equations) The two roots of a quadratic equation, for example, , can be obtained using the following formula: r1 = (-b + sqrt(b^2 - 4ac) / (2a) and r1 = (-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 real roots....
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 =...
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...
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 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...
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...