• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

mon0l1t Jun 18th, 2019 (edited) 56 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(-2, 2, 0.25, 0.001, y);
13.     cout << endl;
14.     cout << setw(8) << "x" << setw(15) << "s(x)" << setw(10) << "k" << endl;
15.     tabl(-2, 2, 0.25, 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 (pi*(pi - 2 * abs(x))) / 8;
33. }
34. double s(double x, double eps, int &k)
35. {
36.     double  c, sum;
37.     sum = c = x;
38.     k = 1;
39.     while (fabs(c) > eps)
40.     {
41.
42.         c = cos((2 * k - 1)*x) / pow((2 * k - 1), 2);
43.
44.         sum += c;
45.         k++;
46.     }
47.     return sum;
48. }
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.

Top