forked from randerson112358/C-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquadratic_formula.c
More file actions
47 lines (36 loc) · 1.2 KB
/
Copy pathquadratic_formula.c
File metadata and controls
47 lines (36 loc) · 1.2 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
38
39
40
41
42
43
44
45
46
47
# include <stdio.h>
# include <math.h>
/* This program shows factors for a quadratic
equation using the quadratic formula
created by: Rodney T. Anderson
*/
int main(void)
{
int a,b,c;
int x1,x2;
printf("Quadratic equation in the form: Ax^2 + Bx + C = 0\n");
printf("A: ");
scanf("%d", &a);
printf("B: ");
scanf("%d", &b);
printf("C: ");
scanf("%d",&c);
if(b*b < 4*a*c) // its an imaginary number
{
printf("Non real number \n");
x1 = (-b+sqrt(4*a*c- b*b))/ (2*a);// quadratic equation
x2 = (-b-sqrt(4*a*c -b*b ))/ (2*a);// quadratic equation
printf("\nfactors for the equation is : ");
printf("(x + %d)(x + %d)\n", -1*x1, -1*x2);
printf("\nx = %di, y= %di\n\n", x1,x2);
}
else // else if its real number
{
x1 = (-b+sqrt(b*b - 4*a*c))/ (2*a);// quadratic equation
x2 = (-b-sqrt(b*b - 4*a*c))/ (2*a);// quadratic equation
printf("\nfactors for the equation is : ");
printf("(x + %d)(x + %d)\n", -1*x1, -1*x2);
printf("\nx = %d, x= %d\n\n", x1,x2);
}
system("pause");
}