Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<math.h>
- #include<iomanip>
- #include<iostream>
- using namespace std;
- float func(float e, float x , int &n)
- {
- float s = 0.0, a = 1.0, singl=1.0;
- n = 0;
- while (fabs(a) >= e)
- {
- s += a;
- a = singl*pow(x,n) / ((n + 1.0) * (n + 4.0));
- cout<<"a="<<a<<endl;
- singl=-singl;
- n++;
- }
- return s;
- }
- int main()
- {
- float a, b, e, h, x;
- cin >> a >> b >> h >> e;
- int n, i;
- x = a;
- cout << func(x, e, n)<< endl;
- while (x = a, i = 1, x <= b, x += h, i++)
- cout << fixed<< i<< " "<< x << " " << setprecision(10) << func(x, e, n) << " "<< n << " " << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement