-
Notifications
You must be signed in to change notification settings - Fork 9
/
quadratic.c
53 lines (49 loc) · 1.25 KB
/
quadratic.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
/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/
#include<stdio.h>
#include<math.h>
main()
{
int a,b,c;
float disc,r1,r2;
for(;;)
{
printf("\nEnter the non Zero co-efficients a, b,c\n");
scanf("%d%d%d",&a,&b,&c);
if((a==0) || (b==0) || (c==0))
{
printf("\nPlease enter non zero co-efficients \n");
}else{
disc=((b*b)-(4*a*c));
if(disc>0)
{
printf("Roots are Real:\n");
r1=(-b-(sqrt(disc)))/(2.0*a);
r2=(-b+(sqrt(disc)))/(2.0*a);
printf("Roots are:%f and %f \n", r1,r2);
}
else if(disc<0)
{
printf("Roots are Imaginary:\n");
r1=-b/(2.0*a);
printf("First root: %lf +%fi \n", r1,sqrt(-disc)/(2.0*a));
printf("Second root:%lf -%lfi\n", r1,sqrt(-disc)/(2.0*a));
}
else
{
printf("Roots are Equal\n");
r1= -b/(2.0*a);
printf("Equal; roots are:%f and %f \n", r1,r1);
}
return 0;
}
}
}