-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.c
More file actions
36 lines (31 loc) · 841 Bytes
/
4.c
File metadata and controls
36 lines (31 loc) · 841 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
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c, d, r1, r2, real, imag;
printf("Enter values of a, b and c: ");
scanf("%f %f %f", &a, &b, &c);
d = b*b - 4*a*c; // discriminant
if (d > 0)
{
r1 = (-b + sqrt(d)) / (2*a);
r2 = (-b - sqrt(d)) / (2*a);
printf("Roots are real and different\n");
printf("Root 1 = %.2f\nRoot 2 = %.2f", r1, r2);
}
else if (d == 0)
{
r1 = -b / (2*a);
printf("Roots are real and equal\n");
printf("Root = %.2f", r1);
}
else
{
real = -b / (2*a);
imag = sqrt(-d) / (2*a);
printf("Roots are complex\n");
printf("Root 1 = %.2f + %.2fi\n", real, imag);
printf("Root 2 = %.2f - %.2fi", real, imag);
}
return 0;
}