fork(9) download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. double tangent(double x, double accuracy) {
  6. int i = 1;
  7. double cos = 1, sin = x, intermediateValueCos = 1, intermediateValueSin = x;
  8. x = fmod(x, M_PI);
  9. while (fabs(intermediateValueCos *= - x * x / (2 * i * (2 * i - 1))) > accuracy
  10. && fabs(intermediateValueSin *= - x * x / (2 * i * (2 * i + 1))) > accuracy) {
  11. cos += intermediateValueCos;
  12. sin += intermediateValueSin;
  13. i++;
  14. }
  15. return sin / cos;
  16. }
  17.  
  18. int main() {
  19. double x, accuracy;
  20. cin >> x >> accuracy;
  21. cout << tangent(x, accuracy);
  22. return 0;
  23. }
Time limit exceeded #stdin #stdout 5s 3460KB
stdin
3.1415
stdout
Standard output is empty