-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6B02.c
34 lines (31 loc) · 1.08 KB
/
6B02.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
30
31
32
33
34
#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c;
float root1, root2;
float discriminant;
printf("Enter value of a , b and c = ");
scanf("%f %f %f",&a,&b,&c);
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
// Two distinct real roots
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("Roots are real and different.\n");
printf("Root 1 = %.2f\n", root1);
printf("Root 2 = %.2f\n", root2);
} else if (discriminant == 0) {
// Two equal real roots
root1 = root2 = -b / (2 * a);
printf("Roots are real and same.\n");
printf("Root 1 = Root 2 = %0.0f\n",root1);
} else {
// Complex roots
float realPart = -b / (2 * a);
float imaginaryPart = sqrt(-discriminant) / (2 * a);
printf("Roots are complex and different.\n");
printf("Root 1 = %.2f + %.2fi\n", realPart, imaginaryPart);
printf("Root 2 = %.2f - %.2fi\n", realPart, imaginaryPart);
}
}