Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- int main()
- {
- float x, y, e, q, k = 0, s = 0;
- printf("Input x, if 0<|x|<1, input e, if 0<e<0.0001\n");
- scanf("%f%f", &x, &e);
- y = cos(x);
- do {
- int fact = 1, n = 2*k;
- for (int c = 1; c <= n; c++){
- fact = fact * c;
- }
- s += pow(-1, k) * pow(x, (2*k))/fact;
- k++;
- } while(fabs(s - y)>e);
- q = fabs(s - y);
- printf("Y(x) = %0.10f\nS(x) = %0.10f\n|S(x) - Y(x)| = %0.10f\n", y, s, q);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement