fork(1) download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. double a, b, c;
  9. double delta, pdelta;
  10. double x1, x2;
  11.  
  12. // ===== PRZYKLAD 1 =====
  13. a = 3;
  14. b = 4;
  15. c = 5;
  16.  
  17. cout << "Przyklad 1: 3x^2 + 4x + 5 = 0" << endl;
  18.  
  19. delta = b*b - 4*a*c;
  20. cout << "Delta = " << delta << endl;
  21.  
  22. if (delta > 0) {
  23. pdelta = sqrt(delta);
  24. x1 = (-b - pdelta) / (2*a);
  25. x2 = (-b + pdelta) / (2*a);
  26. cout << "x1 = " << x1 << endl;
  27. cout << "x2 = " << x2 << endl;
  28. }
  29. else if (delta == 0) {
  30. x1 = -b / (2*a);
  31. cout << "x = " << x1 << endl;
  32. }
  33. else {
  34. cout << "Brak pierwiastkow rzeczywistych" << endl;
  35. }
  36.  
  37. cout << endl;
  38.  
  39. // ===== PRZYKLAD 2 =====
  40. a = 1;
  41. b = 10000;
  42. c = 1;
  43.  
  44. cout << "Przyklad 2: x^2 + 10000x + 1 = 0" << endl;
  45.  
  46. delta = b*b - 4*a*c;
  47. cout << "Delta = " << delta << endl;
  48.  
  49. if (delta > 0) {
  50. pdelta = sqrt(delta);
  51. x1 = (-b - pdelta) / (2*a);
  52. x2 = (-b + pdelta) / (2*a);
  53. cout << "x1 = " << x1 << endl;
  54. cout << "x2 = " << x2 << endl;
  55. }
  56. else if (delta == 0) {
  57. x1 = -b / (2*a);
  58. cout << "x = " << x1 << endl;
  59. }
  60. else {
  61. cout << "Brak pierwiastkow rzeczywistych" << endl;
  62. }
  63.  
  64. return 0;
  65. }
  66.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Przyklad 1: 3x^2 + 4x + 5 = 0
Delta = -44
Brak pierwiastkow rzeczywistych

Przyklad 2: x^2 + 10000x + 1 = 0
Delta = 1e+08
x1 = -10000
x2 = -0.0001