fork(4) download
  1. #include <iostream>
  2. #include <complex>
  3.  
  4. int main()
  5. {
  6. std::complex<double> a = 3.0;
  7. std::complex<double> b = 2.0;
  8. std::complex<double> c = 1.0;
  9.  
  10. std::complex<double> d = sqrt(pow(b,2)- 4.0*a*c);
  11. std::complex<double> r1 = (-b + d)/(2.0*a);
  12. std::complex<double> r2 = (-b - d)/(2.0*a);
  13. std::cout << "The answers are " << std::showpos << '\n'
  14. << r1.real() << " " << r1.imag() << "i\n"
  15. << r2.real() << " " << r2.imag() << "i\n";
  16. }
  17.  
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
The answers are 
-0.333333 +0.471405i
-0.333333 -0.471405i