Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main() {
- float EPS = 0;
- long double EP = 1;
- long double x = 0;
- printf("Enter EPS(0 < EPS < 1) = ");
- if(scanf("%f", &EPS) != 1)
- {
- printf("Error.\n");
- return 0;
- }
- printf("Enter x = ");
- if(scanf("%Lf", &x) != 1)
- {
- printf("Error.\n");
- return 0;
- }
- long double y = 1;
- long double powx = x*x*(-1);
- long double powxOld = powx;
- long int factorial = 2;
- long int factorialOld = factorial;
- long int f = 2;
- if(EPS >= 1 || EPS <= 0)
- {
- printf("Error EPS.\n");
- return 0;
- }
- int k = 0;
- printf("cos(x) = %f;\n", cos(x));
- while(fabsl(EP) > EPS) // В зависимости от компилятора, если будет выдавать ошибку попробуй вместо fabsl fabs
- {
- EP = (long double) powx/factorial;
- y = y + EP;
- powx = powx*x*x*(-1);
- factorial = factorial*(f + 1)*(f + 2);
- if(factorial < factorialOld || fabsl(powx) < powxOld)
- {
- printf("OverFlow\n");
- return 0;
- }
- factorialOld = factorial;
- powxOld = powx;
- f = f + 2;
- k++;
- }
- printf("Teilor = %Lf\n", y);
- return 0;
- }
Add Comment
Please, Sign In to add comment