Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main() {
- float a, b, c;
- float d;
- cout << "Enter a: ";
- cin >> a;
- cout << "Enter b: ";
- cin >> b;
- cout << "Enter c: ";
- cin >> c;
- cout << "Your equation is: " << a << "x^2 + " << b << "x + "<< c << " = 0" << endl;
- cout << "D = " << b << "^2 - 4" << a << c << endl;
- d = pow(b, 2) - (4 * a * c);
- cout << "D = " << d << endl;
- if (d < 0) {
- cout << "This equation hasn`t roots";
- }
- else if (d == 0) {
- float x1;
- x1 = ((-1) * b - sqrt(d)) / (2 * a);
- cout << "x = " << x1;
- }
- else {
- float x1, x2;
- x1 = (((-1) * b) - sqrt(d)) / (2 * a);
- x2 = (((-1) * b) + sqrt(d)) / (2 * a);
- cout << "x1 = " << x1 << endl;
- cout << "x2 = " << x2 << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement