-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path10.c
More file actions
26 lines (26 loc) · 798 Bytes
/
Copy path10.c
File metadata and controls
26 lines (26 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c, discriminant, root1, root2, realPart, imagPart;
printf("Enter a, b and c: ");
scanf("%f %f %f", &a, &b, &c);
discriminant = b * b - 4 * a * c;
if (discriminant > 0)
{
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("Roots are: %.2f and %.2f", root1, root2);
}
else if (discriminant == 0)
{
root1 = root2 = -b / (2 * a);
printf("Roots are: %.2f and %.2f", root1, root2);
}
else
{
realPart = -b / (2 * a);
imagPart = sqrt(-discriminant) / (2 * a);
printf("Roots are: %.2f + %.2fi and %.2f - %.2fi", realPart, imagPart, realPart, imagPart);
}
}