Advertisement
sheredega

task 19

Nov 4th, 2022
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     float a, b, c;
  8.     float d;
  9.     cout << "Enter a: ";
  10.     cin >> a;
  11.     cout << "Enter b: ";
  12.     cin >> b;
  13.     cout << "Enter c: ";
  14.     cin >> c;
  15.     cout << "Your equation is: " << a << "x^2 + " << b << "x + "<< c << " = 0" << endl;
  16.     cout << "D = " << b << "^2 - 4" << a << c << endl;
  17.     d = pow(b, 2) - (4 * a * c);
  18.     cout << "D = " << d << endl;
  19.     if (d < 0) {
  20.         cout << "This equation hasn`t roots";
  21.     }
  22.     else if (d == 0) {
  23.         float x1;
  24.         x1 = ((-1) * b - sqrt(d)) / (2 * a);
  25.         cout << "x = " << x1;
  26.     }
  27.     else {
  28.         float x1, x2;
  29.         x1 = (((-1) * b) - sqrt(d)) / (2 * a);
  30.         x2 = (((-1) * b) + sqrt(d)) / (2 * a);
  31.         cout << "x1 = " << x1 << endl;
  32.         cout << "x2 = " << x2 << endl;
  33.     }
  34.     return 0;    
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement