Advertisement
dllbridge

Untitled

Oct 24th, 2020 (edited)
2,096
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1.  
  2. //  Решение квадратного уравнения.
  3. //  Solving a quadratic  equation.
  4.  
  5.  
  6. #include <stdio.h>
  7. #include  <math.h>
  8.  
  9. float   a,
  10.         b,
  11.         c,      
  12.        x1,
  13.        x2,
  14.         D,                         //  discriminant
  15.       res;                  // sqrt of discriminant
  16.  
  17. ////////////////////////////////////////////////////
  18. int main()                                        //
  19. {
  20.    
  21.     printf("a = "); scanf("%f", &a);
  22.     printf("b = "); scanf("%f", &b);
  23.     printf("c = "); scanf("%f", &c);
  24.  
  25.     D = (b*b) - (4*a*c);
  26.    
  27.     if(D < 0) {
  28.        
  29.        printf("\nDiscriminant < 0, no root.");      
  30.        return 0;      
  31.     }        
  32.    
  33.     res = sqrt(D);
  34.        
  35.     if(D > 0) {  
  36.        
  37.        x1 = (-b + res)/(2 * a);
  38.        x2 = (-b - res)/(2 * a);
  39.    
  40.        printf("\nDiscriminant > 0 (2 root's): \n");
  41.        printf("x1 = %6.2f \n", x1);
  42.        printf("x2 = %6.2f \n", x2);       return 0;    
  43.     }
  44.    
  45.     x1 = (-b)/(2 * a);
  46.    
  47.     printf("\nDiscriminant = 0, only one solution. \n");
  48.     printf("x = %.2f", x1);
  49.  
  50. return 0;  
  51. }
  52.  
  53.  
  54.  
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement