fork download
  1. #include <iostream>
  2. #include <complex>
  3.  
  4. std::pair< std::complex<double>, std::complex<double> > Quad(double a, double b, double c)
  5. {
  6. std::complex<double> d = b*b - 4*a*c;
  7. return { (-b+std::sqrt(d))/(2*a), (-b-std::sqrt(d))/(2*a) };
  8. }
  9.  
  10. int main()
  11. {
  12. double x = 10;
  13. double y = -1;
  14. double z = 1;
  15. std::cout << "The solutions are: " << Quad(x,y,z).first << " and " << Quad(x,y,z).second << '\n';
  16. }
  17.  
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
The solutions are: (0.05,0.31225) and (0.05,-0.31225)