Advertisement
mon0l1t

Untitled

Jun 18th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <iomanip>
  4. using namespace std;
  5. typedef double(*uf)(double, double, int &);
  6. void tabl(double, double, double, double, uf);
  7. double y(double, double, int &);
  8. double s(double, double, int &);
  9. int main()
  10. {
  11.     cout << setw(8) << "x" << setw(15) << "y(x)" << setw(10) << "k" << endl;
  12.     tabl(0.1, 0.8, 0.1, 0.001, y);
  13.     cout << endl;
  14.     cout << setw(8) << "x" << setw(15) << "s(x)" << setw(10) << "k" << endl;
  15.     tabl(0.1, 0.8, 0.1,0.001, s);
  16.     return 0;
  17. }
  18. void tabl(double a, double b, double h, double eps, uf fun)
  19. {
  20.     int k = 0;
  21.    
  22.         double sum;
  23.     for(double x = a; x<b + h / 2; x += h)
  24.     {
  25.         sum = fun(x, eps, k);
  26.         cout << setw(8) << x << setw(15) << sum << setw(10) << k << endl;
  27.     }
  28. }
  29. double y(double x, double eps, int &k)
  30. {
  31.     double pi = 3.14;
  32.     return sin(x);
  33. }
  34. double s(double x, double eps, int &k)
  35. {
  36.     double a, c, sum;
  37.     sum = a = c = x;
  38.     k = 1;
  39.     while(fabs(c)>eps)
  40.     {
  41.         c = pow(x, 2) / (2 * k*(2 * k + 1));
  42.         a *= -c;
  43.         sum += a;
  44.         k++;
  45.     }
  46.     return sum;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement