Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- double power(double x, int n)
- {
- double res = 1;
- for (int i = 0; i < n; i++)
- {
- res *= x;
- }
- return res;
- }
- void abs(double* b)
- {
- if((*b)<0)
- (*b)*= -1;
- }
- double term(double x, int n)
- {
- int a = 0, b = 0;
- double c = 0;
- a = power(-1, n);
- b = 2 * n + 1;
- c = power(x, b);
- return((a*c / b));
- }
- double arctan(double x)
- {
- abs(&x);
- double res = 0;
- int n = 0;
- double t = 9999;
- while (t >= 0.0001)
- {
- t = term(x, n);
- res += t;
- n++;
- abs(&t);
- }
- return res;
- }
- int main()
- {
- double res;
- double x;
- //scanf_s("%lf", &x);
- res = arctan(0.5);
- printf("%.5lf\n", res);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement