Advertisement
rafikamal

Find the Roots of a Quadratic Equation

Jan 3rd, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. int main()
  4. {
  5.     double a, b, c;
  6.     double D;
  7.     double r1, r2;
  8.    
  9.     printf("Enter the value of a: ");
  10.     scanf("%lf", &a);
  11.     printf("Enter the value of b: ");
  12.     scanf("%lf", &b);
  13.     printf("Enter the value of c: ");
  14.     scanf("%lf", &c);
  15.    
  16.     D = b*b - 4*a*c;
  17.    
  18.     if(D < 0)
  19.         printf("Roots are imaginary\n");
  20.     else
  21.     {
  22.         r1 = (-b + sqrt(D)) / (2*a);
  23.         r2 = (-b - sqrt(D)) / (2*a);
  24.        
  25.         printf("Root 1 = %lf\n", r1);
  26.         printf("Root 2 = %lf\n", r2);
  27.     }
  28.    
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement