-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfour.c
More file actions
38 lines (28 loc) · 798 Bytes
/
four.c
File metadata and controls
38 lines (28 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
27
28
29
30
31
32
33
34
35
36
37
38
// Program to find out the roots of quadratic equation.
#include<stdio.h>
#include<math.h>
int main() {
float a, b, c;
float root1, root2, D;
printf("Enter the value for a - ");
scanf("%f", &a);
printf("Enter the value for b - ");
scanf("%f", &b);
printf("Enter the value for c - ");
scanf("%f", &c);
D = (b*b) - 4 * a * c;
if(D > 0) {
root1 = (-b + sqrt(D)) / (2 * a);
root2 = (-b - sqrt(D)) / (2 * a);
printf("Roots are real and different.\n");
printf("%.2f\n", root1);
printf("%.2f\n", root2);
} else if(D == 0) {
root1 = -b / (2 * a);
printf("Roots are real and equal.\n");
printf("%.2f\n", root1);
} else {
printf("Roots are imaginary");
}
return 0;
}