fork(17) download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. double myAtan(double x, int n) {
  6. double a = x;
  7. double sum = a;
  8. double b = a;
  9. double E = 1 / n;
  10. for(int i = 1; a > E; i++){
  11. b *= - x * x;
  12. a *= b / (2 * i + 1);
  13. sum += a;
  14. }
  15. return sum;
  16. }
  17.  
  18. int main() {
  19. double x;
  20. int n;
  21. cin >> x >> n;
  22. cout << "my arctg: " << myAtan(x, n) << endl;
  23. cout << "arctg: " << atan(x) << endl;
  24. cout << "|arctg - my arctg| = " << abs(myAtan(x, n) - atan(x)) << endl;
  25. return 0;
  26. }
Success #stdin #stdout 0s 3464KB
stdin
1
1000
stdout
my arctg: 0.666667
arctg: 0.785398
|arctg - my arctg| = 0.118731