fork(6) download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. double cos (double x, double e) {
  5. double x2,c,n,f,z;
  6. x2= x*x;
  7. f= 2;
  8. c= 1;
  9. n= 2;
  10. z= -1;
  11. while ((x2/f)>=e) {
  12. c=c+z*x2/f;
  13. n=n+2;
  14. x2=x2*x*x;
  15. f=f*(n-1)*n;
  16. z=z*(-1);
  17. }
  18. return c;
  19. }
  20. int main() {
  21. double x,e;
  22. cin>>x;
  23. cin>>e;
  24.  
  25.  
  26. cout<<cos(x,e)<<endl;
  27. return 0;
  28. }
Success #stdin #stdout 0s 3464KB
stdin
1
0.001
stdout
0.540278