fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. double arcSinTaylor(double x) {
  9. double result = x, oldResult = -1000;
  10. double q = x;
  11. x = x*x;
  12. int i=1;
  13. while (result!=oldResult) {
  14. oldResult = result;
  15. q *=x*i/(i+1);
  16. i +=2;
  17. result += q/i;
  18. }
  19. return result;
  20. }
  21.  
  22. int main() {
  23. double x, precision;
  24. while (cin >> x) {
  25. double a = arcSinTaylor(x);
  26. double b = asin(x);
  27. cout << setw(6) << x
  28. << setw(10) << setprecision(6) << a
  29. << setw(10) << b
  30. << setw(10) << setprecision(2) << b-a << endl;
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0s 3476KB
stdin
0
0.25
0.5
0.75
-0.25
-0.5
-0.75
stdout
     0         0         0         0
  0.25   0.25268   0.25268   6.6e-18
   0.5  0.523599  0.523599  -5.4e-17
  0.75  0.848062  0.848062   3.5e-18
 -0.25  -0.25268  -0.25268  -6.6e-18
  -0.5 -0.523599 -0.523599   5.4e-17
 -0.75 -0.848062 -0.848062  -3.5e-18