Advertisement
18126

Day1(ex2)

Jul 7th, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.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; // D = b**b - 4*a*c
  14.     if(fabs(D) > 0.001) {
  15.         x1 = x2 = -b / (2*a); // -b / (2*a)
  16.         printf("x1 = x2 = %.2f\n", x1);
  17.     } else if (D > 0) {
  18.         x1 = (-b + sqrt(D)) / (2*a);
  19.         x2 = (-b - sqrt(D)) / (2*a);
  20.         printf("x1 = %.2f\nx2 = %.2f\n", x1, x2);
  21.     } else {
  22.         printf("No real roots. :( (D = 0)");
  23.     }
  24.     return 0;
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement