darkor

Igor_Lab_3_v2

Nov 18th, 2020
577
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. 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.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×