Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- double f(double x, double eps)
- {
- double v, sum = x;
- long n = 1;
- double fn = pow(x,3)/6.0;
- while(eps < fabs(fn))
- {
- sum += fn;
- n += 1;
- fn *= (2*n - 1)*(2*n - 1)*x*x;
- fn /= 2*n*(2*n + 1);
- }
- return sum;
- }
- int main()
- {
- char sign[] = " ";
- double x, fx, dx = 0, xn = 0, xk = 0, eps = 0;
- printf("Enter xn : ");scanf("%lf",&xn);
- printf("Enter xk : ");scanf("%lf",&xk);
- printf("Enter dx : ");scanf("%lf",&dx);
- printf("Enter eps: ");scanf("%lf",&eps);
- printf("|-----------------------------------|\n");
- printf("| x | f(x) | asin |(sin-f)/f|\n");
- printf("|-----------------------------------|\n");
- for(x = xn; x <= xk; x += dx)
- {
- fx = f(x,eps);
- if(x < 0)
- sign[0] = '\0';
- else
- sign[0] = ' ';
- printf("|%s%.4f |%s%.4f |%s%.4f|%s%.4f |\n",
- sign,x,sign,fx,sign,asin(fx),sign,(sin(x) != 0 ? fabs(sin(x) - fx)/sin(x) : 0));
- }
- printf("|-----------------------------------|\n");
- printf("Press any key to continue\n");
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement