Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <iostream>
- #include <iomanip>
- using namespace std;
- double f (double x, double eps, int& n)
- {
- double step = 1;
- double s = 0;
- int k=1;
- int fact=1;
- int t = -1;
- while (fabs(step)>=eps)
- {
- s += step;
- fact *= (2*k+2)*(2*k+3);
- step *= t*x*x/fact;
- n ++;
- k ++;
- t = -t;
- }
- return s;
- }
- int main (void)
- {
- double eps;
- double a = 0.0;
- const double b = 1.0;
- const double h = 0.1;
- cin >> eps;
- int i = 1;
- cout << "No\t x \t F(x) \t count\n";
- for (; a<= b; a += h)
- {
- int n = 0;
- double fx = f(a, eps, n);
- cout <<setw(3) << i << " \t" << setw(5) << a << "\t" << setw(10) << fx << "\t" << n << endl;
- i++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment