Advertisement
Zeshin

task2

Jul 5th, 2021
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 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("a = ");
  8.     scanf("%f",&a);
  9.     printf("b = ");
  10.     scanf("%f", &b);
  11.     printf("c = ");
  12.     scanf("%f", &c);
  13.     D = b*b - 4*a*c;
  14.     if(fabs(D) < 0.001)
  15.     {
  16.         x1 = x2 = -b/(2*a);
  17.         printf("x1 = x2 = %.2f\n", x1);
  18.     }
  19.     else if(D>0)
  20.     {
  21.         x1 = (-b + sqrt(D)) / (2*a);
  22.         x2 = (-b - sqrt(D)) / (2*a);
  23.         printf("x1 =  %.2f\nx2 = %.2f\n", x1, x2);
  24.     }
  25.     else
  26.     {
  27.         printf("No real roots");
  28.     }
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement