fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. int main()
  5. {
  6. double theta;
  7. const double max = 6.28318; //estimate of 2pi
  8. const int iterations = 20; //number of times to iterate - 1( the zero )
  9. const double threshold = 0.0000001;
  10.  
  11. for( theta = 0.0; theta < max + threshold; theta += max / iterations )
  12. {
  13. std::cout << "Cos(" << theta << ") = " << cos( theta ) << std::endl;
  14. //repeat for sin and tan.
  15. }
  16. return 0;
  17. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Cos(0) = 1
Cos(0.314159) = 0.951057
Cos(0.628318) = 0.809017
Cos(0.942477) = 0.587786
Cos(1.25664) = 0.309018
Cos(1.57079) = 1.32679e-06
Cos(1.88495) = -0.309015
Cos(2.19911) = -0.587784
Cos(2.51327) = -0.809016
Cos(2.82743) = -0.951056
Cos(3.14159) = -1
Cos(3.45575) = -0.951057
Cos(3.76991) = -0.809019
Cos(4.08407) = -0.587788
Cos(4.39823) = -0.309021
Cos(4.71239) = -3.98038e-06
Cos(5.02654) = 0.309013
Cos(5.3407) = 0.587782
Cos(5.65486) = 0.809014
Cos(5.96902) = 0.951055
Cos(6.28318) = 1