-
Notifications
You must be signed in to change notification settings - Fork 0
/
roots.c
53 lines (42 loc) · 1.29 KB
/
roots.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*Created By 22CE071_Jalay*/
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c, root1, root2, disc, imaginary;
printf("Here is the standard format of quadratic equation: ax2 + bx + c = 0\n");
printf("enter the value of a: ");
scanf("%f", &a);
printf("enter the value of b: ");
scanf("%f", &b);
printf("enter the value of c: ");
scanf("%f", &c);
disc = (b * b) - (4 * a * c);
switch (disc > 0)
{
case 1:
/* If disc is positive */
root1 = (-b + sqrt(disc)) / (2 * a);
root2 = (-b - sqrt(disc)) / (2 * a);
printf("Two distinct and real roots are: %.2f and %.2f", root1, root2);
break;
case 0:
/* If disc is negative */
switch (disc < 0)
{
case 1:
/* If disc is negative */
root1 = root2 = -b / (2 * a);
imaginary = sqrt(-disc)/(2*a);
printf("Two complex roots are: %.2f + i%.2f and %.2f - i%.2f", root1, imaginary, root2, imaginary);
break;
case 0:
/* If disc is zero */
root1 = root2 = -b / (2 * a);
printf("Two equal and real roots are: %.2f and %.2f", root1, root2);
break;
}
}
printf("\n\nCreated By 22CE071_Jalay\n\n");
return 0;
}