fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. double a = 1;
  8. double b = 10000;
  9. double c = 1;
  10.  
  11. cout << "Rownanie: " << a << "x^2 + " << b << "x + " << c << " = 0" << endl;
  12.  
  13. double delta = b * b - 4 * a * c;
  14.  
  15. if (delta < 0) {
  16. cout << "Brak pierwiastkow rzeczywistych." << endl;
  17. return 0;
  18. }
  19.  
  20. // Obliczamy jeden pierwiastek
  21. double x1 = (-b - sqrt(delta)) / (2 * a);
  22.  
  23. // Drugi pierwiastek z Viete’a
  24. double x2 = c / (a * x1);
  25.  
  26. cout << "Pierwiastki rownania:" << endl;
  27. cout << "x1 = " << x1 << endl;
  28. cout << "x2 = " << x2 << endl;
  29.  
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
Rownanie: 1x^2 + 10000x + 1 = 0
Pierwiastki rownania:
x1 = -10000
x2 = -0.0001