fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. int main() {
  7. double a = 1, b = -2, c = 10;
  8. double discriminant = b * b - 4 * a * c;
  9.  
  10. double realPart = -b / (2 * a);
  11. double imaginaryPart = sqrt(abs(discriminant)) / (2 * a);
  12.  
  13. cout << fixed << setprecision(4);
  14. cout << realPart << " + " << imaginaryPart << "i" << endl;
  15. cout << realPart << " - " << imaginaryPart << "i" << endl;
  16.  
  17. return 0;
  18. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
1.0000 + 3.0000i
1.0000 - 3.0000i