Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include<stdio.h>
  2. double power(double x, int n)
  3. {
  4. double res = 1;
  5.  
  6. for (int i = 0; i < n; i++)
  7. {
  8. res *= x;
  9. }
  10.  
  11. return res;
  12. }
  13.  
  14. void abs(double* b)
  15. {
  16. if((*b)<0)
  17. (*b)*= -1;
  18. }
  19.  
  20. double term(double x, int n)
  21. {
  22. int a = 0, b = 0;
  23. double c = 0;
  24.  
  25. a = power(-1, n);
  26. b = 2 * n + 1;
  27. c = power(x, b);
  28.  
  29. return((a*c / b));
  30. }
  31.  
  32. double arctan(double x)
  33. {
  34. abs(&x);
  35. double res = 0;
  36. int n = 0;
  37. double t = 9999;
  38.  
  39. while (t >= 0.0001)
  40. {
  41. t = term(x, n);
  42.  
  43. res += t;
  44. n++;
  45. abs(&t);
  46. }
  47.  
  48. return res;
  49. }
  50.  
  51.  
  52.  
  53. int main()
  54. {
  55. double res;
  56. double x;
  57.  
  58. //scanf_s("%lf", &x);
  59.  
  60. res = arctan(0.5);
  61. printf("%.5lf\n", res);
  62.  
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement