fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. double a = 1, b = 10000, c = 1;
  9.  
  10. double delta = b*b - 4*a*c;
  11.  
  12. cout << "Rownanie: x^2 + 10000x + 1 = 0" << endl;
  13. cout << "Delta = " << delta << endl;
  14.  
  15. if (delta >= 0)
  16. {
  17. double sqrtDelta = sqrt(delta);
  18.  
  19. // poprawny numerycznie algorytm
  20. double x1 = (-b - sqrtDelta) / (2*a);
  21. double x2 = c / (a * x1);
  22.  
  23. cout << "x1 = " << x1 << endl;
  24. cout << "x2 = " << x2 << endl;
  25. }
  26.  
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Rownanie: x^2 + 10000x + 1 = 0
Delta = 1e+08
x1 = -10000
x2 = -0.0001