Advertisement
semenrbt

Kristina_1.3.3

Feb 4th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5.   float EPS = 0;
  6.   float EP = 1, ep = 1;
  7.   float x = 0;
  8.   printf("Enter EPS(0 < EPS < 1) = ");
  9.     if(scanf("%f", &EPS) != 1)
  10.     {              
  11.         printf("Error.\n");
  12.         return 0;
  13.     }
  14.   printf("Enter x = ");
  15.     if(scanf("%f", &x) != 1)
  16.     {              
  17.         printf("Error.\n");
  18.         return 0;
  19.     }
  20.   long double y = 1;
  21.   float powx = x*x;
  22.   int factorial = 2;
  23.   int f = 2;
  24.   if(EPS >= 1 || EPS <= 0)
  25.   {
  26.     printf("Error EPS.\n");
  27.     return 0;
  28.   }
  29.   printf("cos(x) = %f;\n", cos(x));
  30.   while(ep >= EPS)
  31.   {
  32.     EP = powx/(factorial)*(-1);
  33.     ep = powx/factorial;
  34.     y = y + EP;
  35.     powx = powx*x*x;
  36.     factorial = factorial*(f + 1)*(f + 2);
  37.     f = f + 2;
  38.   }
  39.   printf("Teilor = %lf\n", y);
  40.  
  41.  
  42.  
  43.   return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement