Advertisement
darkor

Igor_Lab_3_v2

Nov 18th, 2020
702
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 <conio.h>
  3. #include <math.h>
  4.  
  5. int main()
  6. {
  7.     float x, y, e, q, k = 0, s = 0;
  8.     printf("Input x, if 0<|x|<1, input e, if 0<e<0.0001\n");
  9.     scanf("%f%f", &x, &e);
  10.  
  11.     y = cos(x);
  12.  
  13.     do {
  14.         int fact = 1, n = 2*k;
  15.  
  16.         for (int c = 1; c <= n; c++){
  17.             fact = fact * c;
  18.         }
  19.        
  20.         s += pow(-1, k) * pow(x, (2*k))/fact;
  21.         k++;
  22.     } while(fabs(s - y)>e);
  23.  
  24.     q = fabs(s - y);
  25.     printf("Y(x) = %0.10f\nS(x) = %0.10f\n|S(x) - Y(x)| = %0.10f\n", y, s, q);
  26.     getch();
  27.     return 0;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement