Guest User

cos^2(x)

a guest
Oct 15th, 2020
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main()
  5. {
  6.     int k = 0;
  7.     double x, e, d, s;
  8.  
  9.     printf("x = ");
  10.     scanf("%lf", &x);
  11.     printf("e = ");
  12.     scanf("%lf", &e);
  13.     printf("cos^2(%e) = ", x);
  14.  
  15.     while (31.416 < x) {
  16.         x = x - 31.416;
  17.     }
  18.     while (x < -31.416) {
  19.         x = x + 31.416;
  20.     }
  21.  
  22.     s = 1;
  23.     d = 1;
  24.     while (e < fabs(d)) {
  25.         k = k + 1;
  26.         d = (-d) * x * x / ((2 * k - 1) * (2 * k));
  27.         s = s + d;
  28.     }
  29.  
  30.     printf("%e\n", s*s);
  31.     printf("%3.3e",(pow(cos(x), 2)));
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment