fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. double arctg(double x, double eps = 1e-10, int n = 0)
  7. {
  8. double t = pow(x,2*n+1)/(2*n+1)*(1-2*(n%2));
  9. if (abs(t) > eps) return arctg(x,eps,n+1) + t;
  10. else return t;
  11. }
  12.  
  13. int main(int argc, char * argv[])
  14. {
  15. for(double x = 0; x < 0.7; x += 0.1)
  16. cout << x << " " << atan(x) << " " << arctg(x) << endl;
  17. }
  18.  
Success #stdin #stdout 0.01s 5428KB
stdin
Standard input is empty
stdout
0   0  0
0.1   0.0996687  0.0996687
0.2   0.197396  0.197396
0.3   0.291457  0.291457
0.4   0.380506  0.380506
0.5   0.463648  0.463648
0.6   0.54042  0.54042