Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main()
- {
- int a, b, c, D;
- float x1, x2;
- bool t;
- cout << "a="; cin >> a;
- cout << "b="; cin >> b;
- cout << "c="; cin >> c;
- if (a == 0)
- {
- cout << "Переменная не соответствует условиям\n";
- }
- else
- {
- D = (b * b) - (4 * a * c);
- if (D < 0)
- {
- cout << "Нет вещественных корней\n";
- t = 1;
- }
- else
- {
- if (D == 0)
- {
- if (b != 0)
- {
- t = 0;
- x1 = (b * (-1)) / (2 * a);
- x2 = x1;
- cout << "Один вещественный корень" << x1 << "\n";
- }
- else
- {
- cout << "b=0, невозможно выполнить -b/(2*a) в случае, если D==0\n";
- }
- }
- else
- {
- t = 1;
- x1 = ((-b) + sqrt(D)) / (2 * a);
- x2 = ((-b) - sqrt(D)) / (2 * a);
- cout << "Два вещественных корня\n";
- cout << "x1=" << x1 << "\n";
- cout << "x2=" << x2 << "\n";
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement