write an algorithm to evaluate following expression ax2+bx+c=0
Answers
Answer:
#include <stdio.h>
#include <math.h>
int main() {
float a, b, c, discriminant, x1, x2, r, i;
printf("coefficient of x^2: ");
scanf("%f", &a);
printf("coefficient of x: ");
scanf("%f", &b);
printf("constant term: ");
scanf("%f", &c);
discriminant = pow(b,2) - 4*a*c;
if(discriminant > 0) {
x1 = (-b + sqrt(discriminant))/(2*a);
x2 = (-b - sqrt(discriminant))/(2*a);
printf("x1 = %.2f \n", x1);
printf("x2 = %.2f \n", x2);
} else if (discriminant == 0) {
x1 = -b/(2*a);
x2 = -b/(2*a);
printf("x1 = %.2f \n", x1);
printf("x2 = %.2f \n", x2);
} else {
r = -b/(2*a);
i = sqrt(-discriminant)/(2*a);
printf("x1 = %.2f +i %.2f \n", r, i);
printf("x2 = %.2f -i %.2f \n", r, i);
}
return 0;
}
Explanation:
ax2 + bx + c
where,
a, b, and c are coefficient and real numbers and also a ≠ 0.
If a is equal to 0 that equation is not valid quadratic equation.
we know , if n² = a
then , n = ±√a
We will try ton comert ax²+ba+c=0, a ≠ 0 into something like x²
Divide both sides by a
Now this equation gives two roots
or
#SPJ2