Advertisement
bangkieu96

QuadEq

Sep 14th, 2019
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "math.h"
  3.  
  4. int main()
  5. {
  6.     float a, b, c, d, x1, x2;
  7.     printf("Input A, B, C for the quadratic equation Ax^2 + Bx + C = 0\n");
  8.     printf("A = "); scanf("%f", &a);
  9.     printf("B = "); scanf("%f", &b);
  10.     printf("C = "); scanf("%f", &c);
  11.     d=b*b-4*a*c;
  12.     printf("d = %.2f\n", d);
  13.     if (a==0) printf("The equation has exactly one root: x = %.2f", -c/b);
  14.     else if (d<0)
  15.     {
  16.         x1=-b/(2*a);
  17.         x2=sqrt(-d)/(2*a);
  18.         printf("The equation has two distinct complex roots.\n");
  19.         printf("x1 = %.2f + %.2fi\n", x1, x2);
  20.         printf("x1 = %.2f - %.2fi", x1, x2);
  21.     }
  22.     else if (d==0)
  23.     {
  24.         printf("The equation has exactly one double root:\nx1 = x2 = %.2f", -b/(2*a));
  25.     }
  26.     else
  27.     {
  28.         x1=(-b+sqrt(d))/(2*a);
  29.         x2=(-b-sqrt(d))/(2*a);
  30.         printf("The equation has two distinct real roots.\nx1 = %.2f\nx2 = %.2f", x1, x2);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement