fork(4) download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. double a, b, c, x1, x2, x3, x4, t1, t2, d, D; bool log=false;
  7. cin>>a;
  8. cin>>b;
  9. cin>>c;
  10. if (a==0) {
  11. if (b!=0) {
  12. if (c==0) {cout<<"X=0";}
  13. else {
  14. if (c/b<0){
  15. x1=sqrt(-(c/b));
  16. x2=-sqrt(-(c/b));
  17. cout<<"X1="<<x1<<"; X2="<<x2;
  18. }
  19. else {cout<<"Нет решений";}
  20. }
  21. }
  22. else {
  23. if (c!=0) {cout<<"Нет решений";}
  24. else {cout<<"X любое";}
  25.  
  26. }
  27. }
  28. else{
  29. D = (b * b - 4 * a * c);
  30. if (D<0) {cout<<"Нет решений";}
  31. else {
  32. d=sqrt(D);
  33. t1=( - b + d )/2.0 / a;
  34. t2=( - b - d )/2.0 / a;
  35. if (t1>0){
  36. x1=sqrt(t1);
  37. x2=-sqrt(t1);
  38. cout<<"X1="<<x1<<"; X2="<<x2<<"; ";
  39. log = true;
  40. }
  41. if (t2>0){
  42. x3=sqrt(t2);
  43. x4=-sqrt(t2);
  44. if (log == true){cout<<"X3="<<x3<<"; X4="<<x4<<";";}
  45. if (log == false){cout<<"X1="<<x3<<"; X2="<<x4<<";";}
  46. }
  47. }
  48. }
  49. }
Success #stdin #stdout 0s 3464KB
stdin
-5 22 -6
stdout
X1=0.540483; X2=-0.540483; X3=2.02679; X4=-2.02679;