Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- unsigned int factorial(unsigned int n)
- {
- if (n == 0)
- return 1;
- return n * factorial(n - 1);
- }
- 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 {
- s += pow(-1, k) * (pow(x, (2*k))/factorial(2*k));
- k++;
- } while(fabs(s - y)>e);
- q = fabs(s - y);
- printf("Y(x) = %0.10f\nS(x) = %0.10f\n|S(x) - Y(x)| = %f\n", y, s, q);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement