Advertisement
Risonna

lab2_n2

Oct 30th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int a, b, c, D;
  8.     float x1, x2;
  9.     bool t;
  10.     cout << "a="; cin >> a;
  11.     cout << "b="; cin >> b;
  12.     cout << "c="; cin >> c;
  13.     if (a == 0)
  14.     {
  15.         cout << "Переменная не соответствует условиям\n";
  16.     }
  17.     else
  18.     {
  19.         D = (b * b) - (4 * a * c);
  20.         if (D < 0)
  21.         {
  22.             cout << "Нет вещественных корней\n";
  23.             t = 1;
  24.         }
  25.         else
  26.         {
  27.                 if (D == 0)
  28.                 {
  29.                     if (b != 0)
  30.                     {
  31.                         t = 0;
  32.                         x1 = (b * (-1)) / (2 * a);
  33.                         x2 = x1;
  34.                         cout << "Один вещественный корень" << x1 << "\n";
  35.                     }
  36.                     else
  37.                     {
  38.                         cout << "b=0, невозможно выполнить -b/(2*a) в случае, если D==0\n";
  39.                     }
  40.                 }
  41.                 else
  42.                 {
  43.                     t = 1;
  44.                     x1 = ((-b) + sqrt(D)) / (2 * a);
  45.                     x2 = ((-b) - sqrt(D)) / (2 * a);
  46.                     cout << "Два вещественных корня\n";
  47.                     cout << "x1=" << x1 << "\n";
  48.                     cout << "x2=" << x2 << "\n";
  49.                 }
  50.         }
  51.     }
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement