Computer Science, asked by prachihonrao06, 2 months ago

write an algorithm to evaluate following expression ax2+bx+c=0​

Answers

Answered by pagaremandar309
3

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:

Answered by Jamestiwari
1

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

 {x}^{2} x \times \frac{b}{a}   +  \frac{c}{a}  = 0

 {x}^{2}  + x \times \frac{b}{a}  =  -   \frac{c}{a}

(x\ +  \frac{b}{2a} )^{2}  -   \frac{b}{4a}  ^{2}  =  -   \frac{c}{a}

(x \times \frac{b}2a)^{2}   =  \frac{ {b}^{2}  - 4ac}{4a}

Now this equation gives two roots

n   =  \frac{ - 6 \sqrt{6 ^{2}  - 4ac} }{2a}

or

n  =  \frac{ - b -  \sqrt{ {b}^{2}  - 4ac } }{2a}

#SPJ2

Similar questions