fork(1) download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. double a, b, c;
  8. double delta, x1, x2;
  9.  
  10. cout << "Podaj a, b, c: ";
  11. cin >> a >> b >> c;
  12.  
  13. delta = b*b - 4*a*c;
  14.  
  15. if (delta < 0) {
  16. cout << "Brak pierwiastkow rzeczywistych" << endl;
  17. } else {
  18. x1 = (-b - sqrt(delta)) / (2*a);
  19. x2 = (-b + sqrt(delta)) / (2*a);
  20.  
  21. cout << "x1 = " << x1 << endl;
  22. cout << "x2 = " << x2 << endl;
  23.  
  24. cout << "\nSprawdzenie wzorow Viete'a:" << endl;
  25. cout << "x1 + x2 = " << x1 + x2 << " (powinno byc " << -b/a << ")" << endl;
  26. cout << "x1 * x2 = " << x1 * x2 << " (powinno byc " << c/a << ")" << endl;
  27. }
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Podaj a, b, c: x1 = -0.5
x2 = -0.5

Sprawdzenie wzorow Viete'a:
x1 + x2 = -1 (powinno byc -1)
x1 * x2 = 0.25 (powinno byc 1.49587)