-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUntitled-1.c
29 lines (24 loc) · 958 Bytes
/
Untitled-1.c
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
27
28
29
#include <stdio.h>
#include <math.h>
int main() {
float a, b, c, discriminant, root1, root2, realPart, imaginaryPart;
printf("Enter coefficients 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 real and different.\n");
printf("root1 = %.2f and root2 = %.2f", root1, root2);
} else if (discriminant == 0) {
root1 = root2 = -b / (2 * a);
printf("Roots are real and same.\n");
printf("root1 = root2 = %.2f;", root1);
} else {
realPart = -b / (2 * a);
imaginaryPart = sqrt(-discriminant) / (2 * a);
printf("Roots are complex and different.\n");
printf("root1 = %.2f + %.2fi and root2 = %.2f - %.2fi", realPart, imaginaryPart, realPart, imaginaryPart);
}
return 0;
}