Advertisement
DevilDaga

EXP5

Mar 10th, 2014
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4. void main()
  5. {
  6.     float a, b, c, d;
  7.     printf("Enter a b and c co-effecients for equation of the form a*x^2 + b*x + c = 0\n");
  8.     scanf("%f %f %f", &a, &b, &c);
  9.     if (a == 0)
  10.         printf("The Equation is not Quadratic!\n");
  11.     else
  12.     {
  13.         d = pow(b, 2) - (4 * a*c);
  14.         if (d < 0)
  15.         {
  16.             printf("Imaginary Roots\n");
  17.             d = sqrt(-d);
  18.             printf("Roots:\nX1 = %.2f  +  i%.2f\nX2 = %.2f  -  i%.2f\n", -b / (2 * a), d / (2 * a), -b / (2 * a), d / (2 * a));
  19.         }
  20.         else
  21.         {
  22.             d = sqrt(d);
  23.             if (d == 0)
  24.             {
  25.                 printf("Roots are equal\n");
  26.                 printf("Roots:\nX = %.2f\n", -b / (2 * a));
  27.             }
  28.             else
  29.             {
  30.                 printf("Roots are unequal\n");
  31.                 printf("Roots:\nX1 = %.2f\nX2 = %.2f\n", (-b + d) / (2 * a), (-b - d) / (2 * a));
  32.             }
  33.         }
  34.     }
  35.     getch();
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement