Advertisement
punidota

Untitled

Sep 18th, 2015
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4.  
  5. double f(double x, double eps)
  6. {
  7.     double v, sum = x;
  8.     long n = 1;
  9.     double fn = pow(x,3)/6.0;
  10.     while(eps < fabs(fn))
  11.     {
  12.         sum += fn;
  13.         n   += 1;
  14.         fn *= (2*n - 1)*(2*n - 1)*x*x;
  15.         fn /= 2*n*(2*n + 1);
  16.     }
  17.     return sum;
  18. }
  19.  
  20. int main()
  21. {
  22.     char sign[] = " ";
  23.     double x, fx, dx = 0, xn = 0, xk = 0, eps = 0;
  24.     printf("Enter xn : ");scanf("%lf",&xn);
  25.     printf("Enter xk : ");scanf("%lf",&xk);
  26.     printf("Enter dx : ");scanf("%lf",&dx);
  27.     printf("Enter eps: ");scanf("%lf",&eps);
  28.     printf("|-----------------------------------|\n");
  29.     printf("|    x   |  f(x)  |  asin |(sin-f)/f|\n");
  30.     printf("|-----------------------------------|\n");
  31.     for(x = xn; x <= xk; x += dx)
  32.     {
  33.         fx = f(x,eps);
  34.         if(x < 0)
  35.             sign[0] = '\0';
  36.         else
  37.             sign[0] = ' ';
  38.         printf("|%s%.4f |%s%.4f |%s%.4f|%s%.4f  |\n",
  39.             sign,x,sign,fx,sign,asin(fx),sign,(sin(x) != 0 ? fabs(sin(x) - fx)/sin(x) : 0));
  40.     }
  41.     printf("|-----------------------------------|\n");
  42.     printf("Press any key to continue\n");
  43.     getch();
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement