-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquadraticeqn.c
35 lines (30 loc) · 937 Bytes
/
quadraticeqn.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
#include<stdio.h>
#include<math.h>
int main()
{
double a, b, c, discriminant, root1, root2, root3, imagnarypart, realpart;
printf("Enter the coefficient of a : \n");
scanf("%lf", &a);
printf("Enter the coefficient of b : \n");
scanf("%lf", &b);
printf("Enter the coefficient of c : \n");
scanf("%lf", &c);
discriminant= pow(b,2)-4*a*c;
if (discriminant>0)
{
root1= (-b + sqrt(discriminant))/2*a;
root2= (-b - sqrt(discriminant))/2*a;
printf("the roots of the given number are %lf and %lf ", root1, root2);
}
else if (discriminant==0)
{
root1=root2= -b / (2*a);
printf("root 1 = %lf and root 2 = %lf", root1, root2);
}
else
{
realpart= -b/(2*a);
imagnarypart= sqrt(-discriminant)/2*a;
printf("root 1 = %lf+%lfi and root 2 is %lf-%lfi", realpart, imagnarypart, realpart, imagnarypart);
}
}