SHARE
TWEET

Untitled

mon0l1t Jun 18th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top