fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. ios_base::sync_with_stdio(false);
  10. cin.tie(NULL);
  11.  
  12. double a, b, c;
  13. if (cin >> a >> b >> c) {
  14. double delta = b * b - 4 * a * c;
  15. if (delta < 0) delta = 0; //có thể có sai số nhỏ khiến delta âm
  16.  
  17. double x1 = (-b - sqrt(delta)) / (2 * a);
  18. double x2 = (-b + sqrt(delta)) / (2 * a);
  19.  
  20. if (x1 > x2) {
  21. swap(x1, x2);
  22. }
  23.  
  24. cout << fixed << setprecision(6) << x1 << " " << x2 << "\n";
  25. }
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty