Advertisement
salron3

Kvadratno uravnenie

Oct 27th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4.  
  5.  
  6. int main()
  7. {
  8.     float a, b, c, d;
  9.     float x1, x2;
  10.  
  11.     printf("Enter a = ");
  12.     scanf("%g", &a);
  13.  
  14.     printf("Enter b = ");
  15.     scanf("%g", &b);
  16.  
  17.     printf("Enter c = ");
  18.     scanf("%g", &c);
  19.  
  20.     if (a == 0)
  21.     {
  22.         x1 = -c / b;
  23.         printf("Poluchava se lineino uravnenie ot vida \"bx + c = 0\"\n");
  24.         printf("x = %g\n", x1);
  25.     }
  26.     else if (b == 0)
  27.     {
  28.         printf("Nqma reshenie\n");
  29.     }
  30.     else if (c == 0)
  31.     {
  32.         printf("Vsqko X e reshenie\n");
  33.     }
  34.     else
  35.     {
  36.         d = b*b - 4 * a*c;
  37.  
  38.         if (d < 0)
  39.         {
  40.             printf("Nqma realni koreni\n");
  41.         }
  42.         else if (d == 0)
  43.         {
  44.             x1 = -b / (2 * a);
  45.             printf("x1 = x2 = %g\n", x1);
  46.         }
  47.         else
  48.         {
  49.             x1 = (-b + sqrt(d)) / (2 * a);
  50.             x2 = (-b - sqrt(d)) / (2 * a);
  51.  
  52.             printf("x1 = %g\n", x1);
  53.             printf("x2 = %g\n", x2);
  54.         }
  55.     }
  56.  
  57.     system("PAUSE");
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement