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;
- cout << setprecision(3);
- cout << "i\t x\t f(x) \t n\n";
- for (x=a,i=1; x<=b; x+=h, i++)
- {func(x,e,n);
- cout<<i<<"\t"<<x<<"\t"<<n<<endl;}
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement