fork(1) download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5.  
  6. int main() {
  7. double x, a, e, b=1, z=1;
  8. int n=0;
  9. cin >> x;
  10. cin >> e;
  11. a = (exp(x) + exp(-x)) / 2;
  12. do
  13. {
  14. z*=(x*x)/((2*n + 1)*(2*n + 2));
  15. b+=z;
  16. n++;
  17. }
  18. while(fabs(a-b) > e);
  19. cout << a << endl;
  20. cout << b << endl;
  21. cout << n << endl;
  22. return 0;
  23. }
Success #stdin #stdout 0s 3476KB
stdin
3
0.02
stdout
10.0677
10.0502
4