Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CalculateTheRoots( float a, float b, float c, float *pd, float *x1, float *x2)
- {
- float d = *pd;
- d = b * b - 4 * a * c;
- if (d >= 0)
- {
- *x1 = (- b + sqrt(d) / (2 * a));
- *x2 = (- b - sqrt(d) / (2 * a));
- }
- else
- {
- *x1 = (- b) / (2 * a);
- *x2 = sqrt(d) / (2 * a);
- }
- *pd = d;
- }
- void TheSolving()
- {
- float a, float b, float c;
- printf("Please write the coefficients: \n");
- scanf("%f %f %f", &a, &b, &c); //coefficients
- float pd, x1, x2; // discriminant and roots
- if (a == 0)
- {
- printf("It's not a quadratic equation\n");
- }
- else
- {
- CalculateTheRoots(a,b,c, *pd, *x1, *x2);
- printf("Discriminant is %f\n", pd);
- printf("Vertex: x = %f, y = %f", (- b / (2 * a)), (- pd / (4 * a)));
- if ( d == 0 )
- printf("The root is %f\n", x1);
- else if (d > 0)
- printf("The roots are %f and %f\n", x1, x2);
- else
- printf("The roots are complex and equals %f +- %f\n" , x1, x2);
- }
- }
- int main()
- {
- TheSolving();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement