forked from mr-robot-2008/c-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroots quad.c
More file actions
37 lines (33 loc) · 1.04 KB
/
roots quad.c
File metadata and controls
37 lines (33 loc) · 1.04 KB
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
#include<stdio.h>
#include<math.h>
int main()
{
printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
float a, b, c, determinant, r1, r2, real, imag;
printf("\n\nEnter coefficients a, b and c: \n\n\n");
scanf("%f%f%f", &a, &b, &c);
determinant == b*b - 4*a*c;
if(determinant > 0) // both roots are real
{
r1 = (-b + sqrt(determinant))/2*a; // Brackets are important
r2 = (-b - sqrt(determinant))/2*a;
printf("\n\n\nRoots are: %.2f and %.2f ", r1, r2);
}
else if(determinant == 0) // both roots are real and equal
{
r1 = r2 = -b/(2*a); // brackets are important
printf("\n\n\nRoots are: %.2f and %.2f ", r1, r2);
}
/*
Determinant < 0 - both roots are imaginary of the
form real + i*imaginary
*/
else
{
real = -b/(2*a);
imag = sqrt(-determinant)/(2*a);
printf("\n\n\nRoots are %.2f + i%.2f and %.2f - i%.2f ", real, imag, real, imag);
}
printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
return 0;
}