Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QCoreApplication>
- #include <iostream>
- #include <cmath>
- using namespace std;
- int a, b, c;
- float x, x1, x2, D;
- int main()
- {
- cout << "Имеем уравнение вида: ax^2+bx+c=0" << endl;
- cout << "Введите значение а:" << endl;
- cin >> a;
- cout << "Введите значение b:" << endl;
- cin >> b;
- cout << "Введите значение c:" << endl;
- cin >>c;
- cout << "Решение уравнения:" << endl;
- if (a == 0) {
- x=(-c)/b;
- cout << "x = " << x << endl;
- }
- if (a != 0) {
- D = pow(b,2)-4*a*c;
- cout << "D =" << D << endl;
- if (D>0) {
- x1 = (-b-sqrt(D))/(2*a);
- x2 = (-b+sqrt(D))/(2*a);
- cout << "x1 =" << x1 << endl;
- cout << "x2 =" << x2 << endl;
- }
- if (D<0) {
- cout << "Уравнение не имеет решений" << endl;
- }
- if (D == 0) {
- x = (-b)/2*a;
- cout << "Уравнение имеет единственный корень: " << x << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement