fork download
  1. #include <iostream>
  2. #include <complex>
  3.  
  4. int main()
  5. {
  6. std::complex<double> const e (2.7182818284590452);
  7. std::complex<double> const i (0.0, 1.0);
  8.  
  9. std::complex<double> theta (3.1415926535897932/6.0);
  10.  
  11. std::complex<double> result = std::pow(e, i*theta);
  12.  
  13. double cosine = result.real();
  14. double sine = result.imag();
  15. double tangent = sine/cosine;
  16.  
  17. std::cout << "sine of pi/6 = " << sine << std::endl;
  18. std::cout << "cosine of pi/6 = " << cosine << std::endl;
  19. std::cout << "tangent of pi/6 = " << tangent << std::endl;
  20. }
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
sine of    pi/6 = 0.5
cosine of  pi/6 = 0.866025
tangent of pi/6 = 0.57735