➽ Program:-
#include<stdio.h>
#include<math.h>
int main()
{
double a, b, c,
discriminant, Root1, Root2, realPart, imaginaryPart;
printf("Enter
coefficients(a,b,c): ");
scanf("%lf
%lf %lf", &a, &b, &c);
discriminant =
b * b - 4 * a * c;
// For
real and different roots
if
(discriminant > 0)
{
Root1
= (-b + sqrt(discriminant)) / (2 * a);
Root2
= (-b - sqrt(discriminant)) / (2 * a);
printf("Root1
= %.2lf \nRoot2 = %.2lf", Root1, Root2);
}
// For
real and equal roots
else if
(discriminant == 0)
{
Root1
= Root2 = -b / (2 * a);
printf("Root1
= Root2 = %.2lf;", Root1);
}
// For
non real roots
else
{
realPart
= -b / (2 * a);
imaginaryPart
= sqrt(-discriminant) / (2 * a);
printf("Root1 = %.2lf+%.2lfi \nRoot2 = %.2f-%.2fi",
realPart, imaginaryPart,realPart, imaginaryPart);
}
return 0;
}
➽ Output:-
0 Comments
Please do not enter any spam link in the comment section.