Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main(void) {
  5.  
  6. double x, x1 = 0.0, x2 = 1.0, e = 0.000001, xvstep, sum = 0.0, hop;
  7.  
  8. while (x2 - x1 > e)
  9. {
  10. x = x1 + (x2 - x1) / 2;
  11. if ((atan(x1) - 5.0 / 7) * (atan(x) - 5.0 / 7) < 0)
  12. x2 = x;
  13. else x1 = x;
  14. }
  15.  
  16. printf("%.7f\n%.8f\n", x, x2 - x1);
  17. int n = 1;
  18. xvstep = x;
  19. sum += x;
  20. e = 0.00001;
  21. //hop = sum - 0.4;
  22.  
  23. /*while (hop > e)*/
  24.  
  25. //while (sum % -> e)
  26.  
  27. while ((int)(sum * 10000.0) % 10 > 0)
  28. {
  29. xvstep = (xvstep * x * x) / (2 * n + 1);
  30.  
  31. sum = sum + n % 2 == 0 ? +xvstep : -xvstep;
  32.  
  33. n++;
  34. //hop = sum - 0.4;
  35. //if (hop < 0)
  36. // hop = hop * (-1);
  37. }
  38. printf("%.6f\n%d\n", sum, n - 1);
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement