Advertisement
reeps

TSANIFIRST

Feb 14th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1.  
  2.  
  3. void CalculateTheRoots( float a, float b, float c, float *pd, float *x1, float *x2)
  4. {
  5.     float d = *pd;
  6.     d = b * b - 4 * a * c;
  7.     if (d >= 0)
  8.     {
  9.         *x1 = (- b + sqrt(d) / (2 * a));
  10.         *x2 = (- b - sqrt(d) / (2 * a));
  11.     }
  12.     else
  13.     {
  14.         *x1 = (- b) / (2 * a);
  15.         *x2 = sqrt(d) / (2 * a);
  16.     }
  17.     *pd = d;
  18. }
  19. void TheSolving()
  20. {
  21.     float a, float b, float c;
  22.     printf("Please write the coefficients: \n");
  23.     scanf("%f %f %f", &a, &b, &c); //coefficients
  24.     float pd, x1, x2; // discriminant and roots
  25.     if (a == 0)
  26.     {
  27.         printf("It's not a quadratic equation\n");
  28.     }
  29.     else
  30.     {
  31.         CalculateTheRoots(a,b,c, *pd, *x1, *x2);
  32.         printf("Discriminant is %f\n", pd);
  33.         printf("Vertex: x = %f, y = %f", (- b / (2 * a)), (- pd / (4 * a)));
  34.         if ( d == 0 )
  35.             printf("The root is %f\n", x1);
  36.         else if (d > 0)
  37.             printf("The roots are %f and %f\n", x1, x2);
  38.         else
  39.             printf("The roots are complex and equals %f +- %f\n" , x1, x2);
  40.     }
  41.    
  42. }  
  43. int main()
  44. {
  45.     TheSolving();
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement