Advertisement
Pafnytiu

сумма 5

Dec 8th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include<math.h>
  2. #include<iomanip>
  3. #include<iostream>
  4. using namespace std;
  5.  
  6.  
  7. float func(float e, float x , int &n)
  8. {
  9. float s = 0.0, a = 1.0, singl=1.0;
  10. n = 0;
  11. while (fabs(a) >= e)
  12. {
  13. s += a;
  14. a = singl*pow(x,n) / ((n + 1.0) * (n + 4.0));
  15. cout<<"a="<<a<<endl;
  16. singl=-singl;
  17. n++;
  18. }
  19. return s;
  20. }
  21.  
  22. int main()
  23.  
  24. {
  25. float a, b, e, h, x;
  26. cin >> a >> b >> h >> e;
  27. int n, i;
  28. cout << setprecision(3);
  29. cout << "i\t x\t f(x) \t n\n";
  30. for (x=a,i=1; x<=b; x+=h, i++)
  31. {func(x,e,n);
  32. cout<<i<<"\t"<<x<<"\t"<<n<<endl;}
  33. system("pause");
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement