Advertisement
Tahamina_Taha

All Roots of a Quadratic Equation

Aug 17th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. #include<conio.h>
  4. //Quadratic equation
  5. int main()
  6. {
  7.     // standard formula ax2 + bx + c = 0
  8.     /*the special Quadratic Formula:
  9.     x = [ -b (+-) sqrt(b^2 - 4ac) ] / 2a */
  10.     double a,b,c,d,x1,x2;
  11.  
  12.     printf("Enter a,b,c:\n");
  13.     scanf("%lf %lf %lf",&a,&b,&c);
  14.  
  15.     d=sqrt(b*b-4*a*c);
  16.     x1=(-b+d)/(2*a);
  17.     x2=(-b-d)/(2*a);
  18.  
  19.     printf("x1=%.0lf\n",x1);
  20.     printf("x2=%.0lf",x2);
  21.      return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement