darkor

Igor_Lab_3

Nov 18th, 2020
338
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4.  
  5. unsigned int factorial(unsigned int n)
  6. {
  7.     if (n == 0)
  8.         return 1;
  9.     return n * factorial(n - 1);
  10. }
  11.  
  12. int main()
  13. {
  14.     float x, y, e, q, k = 0, s = 0;
  15.     printf("Input x, if 0<|x|<1, input e, if 0<e<0.0001\n");
  16.     scanf("%f%f", &x, &e);
  17.  
  18.     y = cos(x);
  19.  
  20.     do {
  21.         s += pow(-1, k) * (pow(x, (2*k))/factorial(2*k));
  22.         k++;
  23.     } while(fabs(s - y)>e);
  24.  
  25.     q = fabs(s - y);
  26.     printf("Y(x) = %0.10f\nS(x) = %0.10f\n|S(x) - Y(x)| = %f\n", y, s, q);
  27.     getch();
  28.     return 0;
  29. }
  30.  
RAW Paste Data