Advertisement
Pafnytiu

сумма 4 - 5

Nov 17th, 2015
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 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. x = a;
  29. cout << func(x, e, n)<< endl;
  30. while (x = a, i = 1, x <= b, x += h, i++)
  31.  
  32. cout << fixed<< i<< " "<< x << " " << setprecision(10) << func(x, e, n) << " "<< n << " " << endl;
  33.  
  34. system("pause");
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement