-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy path9.c
More file actions
32 lines (32 loc) · 776 Bytes
/
9.c
File metadata and controls
32 lines (32 loc) · 776 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
#include <stdio.h>
#include<math.h>
int main()
{
int a,b,c,d;
double x1,x2;
printf("enter the values of a b and c in a quadratic equation");
scanf("%d %d %d",&a,&b,&c);
d=(b*b)-(4*a*c);
if(d>0)
{
printf("\nthe roots are real and distinct");
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("\nthe roots are %lf and %lf",x1,x2);
}
else if(d==0)
{
printf("\nthe roots are real and equal");
x1=(-b)/(2*a);
x2=(-b)/(2*a);
printf("\nthe roots are %lf and %lf",x1,x2);
}
else
{
printf("\nthe roots are imaginary");
x1=-b/(2*a);
x2=sqrt(-d)/(2*a);
printf("\nthe roots are %lf+i%lf and %lf-i%lf",x1,x2,x1,x2);
}
return 0;
}