Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int dis(int a, int b, int c) {
  7.     return b * b - (4 * a * c);
  8. }
  9. int X1(int b, int d, int a) {
  10.     return (-b + sqrt(d)) / (2 * a);
  11. }
  12.  
  13. int main() {
  14.     int a, b, c, d, x1, x2;
  15.     cin >> b >> a >> c;
  16.     d = dis(b, a, c);
  17.     cout << "D = " << d << endl;
  18.     if (d < 0) {
  19.         cout << "Нет решений." << endl;
  20.     }
  21.     else
  22.     if (d == 0) {
  23.         x1 = X1(b, d, a);
  24.     cout << "x1 = " << x1 << endl;
  25.     }
  26.     else
  27.         x1 = X1(b, d, a);
  28.         x2 = (-b - sqrt(d)) / (2 * a);
  29.     cout << "x1 = " << x1 << endl << "x2 = " << x2 << endl;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement