Advertisement
Mary_99

Squere equation

Nov 25th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include<conio.h>
  4. int main()
  5. {
  6.     float a, b, c, delta, x1, x2;
  7.     printf("a = ");
  8.     scanf("%f", &a);
  9.     printf("b = ");
  10.     scanf("%f", &b);
  11.     printf("c = ");
  12.     scanf("%f", &c);
  13.  
  14.     if(a!=0)
  15.     {
  16.         delta = pow(b,2)-4*a*c;
  17.         if(delta < 0)
  18.         {
  19.             printf("no solution\n");
  20.         }
  21.         else if (delta == 0 )
  22.         {
  23.             x1 = x2 = (-b/2*a);
  24.  
  25.         }
  26.         else
  27.         {
  28.             x1 = ((-b- sqrt(delta))/(2*a));
  29.             x2 = ((-b+ sqrt(delta))/(2*a));
  30.         }
  31.         printf("%f, %f", x1, x2);
  32.     }
  33. else printf(" incorrect a value");
  34.  
  35.    return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement