Advertisement
semenrbt

3laba

Feb 12th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.24 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5.   float EPS = 0;
  6.   long double EP = 1;
  7.   long double 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("%Lf", &x) != 1)
  16.     {              
  17.         printf("Error.\n");
  18.         return 0;
  19.     }
  20.   long double y = 1;
  21.   long double powx = x*x*(-1);
  22.   long double powxOld = powx;
  23.   long int factorial = 2;
  24.   long int factorialOld = factorial;
  25.   long int f = 2;
  26.   if(EPS >= 1 || EPS <= 0)
  27.   {
  28.     printf("Error EPS.\n");
  29.     return 0;
  30.   }
  31.   int k = 0;
  32.   printf("cos(x) = %f;\n", cos(x));
  33.   while(fabsl(EP) > EPS) // В зависимости от компилятора, если будет выдавать ошибку попробуй вместо fabsl fabs
  34.   {
  35.     EP = (long double) powx/factorial;
  36.     y = y + EP;
  37.     powx = powx*x*x*(-1);
  38.     factorial = factorial*(f + 1)*(f + 2);
  39.     if(factorial < factorialOld || fabsl(powx) < powxOld)
  40.     {
  41.       printf("OverFlow\n");
  42.       return 0;
  43.     }
  44.     factorialOld = factorial;
  45.     powxOld = powx;
  46.     f = f + 2;
  47.     k++;
  48.   }
  49.   printf("Teilor = %Lf\n", y);
  50.  
  51.  
  52.  
  53.   return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement