fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Depo
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. double x, a, e, b=1, z=1;
  10. int n=0;
  11. Scanner in = new Scanner(System.in);
  12. x= in.nextDouble();
  13. e= in.nextDouble();
  14. a=(Math.exp(x)+ Math.exp(-x))/2;
  15. do{
  16. z*=(x*x)/((2*n + 1)*(2*n + 2));
  17. b+=z;
  18. n++;
  19. }while(Math.abs(a-b) > e);
  20. System.out.println(a);
  21. System.out.println(b);
  22. System.out.println(n);
  23.  
  24. }
  25. }
Success #stdin #stdout 0.15s 321280KB
stdin
1 0.0001
stdout
1.5430806348152437
1.5430555555555556
3