Advertisement
35657

Untitled

Mar 16th, 2024
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void get_roots(double a, double b, double c) {
  6.     double discriminant = b * b - 4 * a * c;
  7.  
  8.     if (discriminant < 0) {
  9.         cout << "Уравнение не имеет корней" << endl;
  10.         return;
  11.     }
  12.     else if (discriminant == 0) {
  13.         cout << "x = " << -b / (2 * a) << endl;
  14.         return;
  15.     }
  16.     else {
  17.         cout << "x1 = " << (-b + sqrt(discriminant)) / (2 * a) << endl;
  18.         cout << "x2 = " << (-b - sqrt(discriminant)) / (2 * a) << endl;
  19.     }
  20. }
  21.  
  22. void get_roots(double a, double b) {
  23.     cout << "x = " << -b / a << endl;
  24. }
  25.  
  26.  
  27.  
  28. int main() {
  29.  
  30.     setlocale(LC_ALL, "ru");
  31.  
  32.     get_roots(2, 6, 4);
  33.     get_roots(6, -2);
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement