Advertisement
AlexandrTalchuk

3.3.11

Dec 29th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <math.h>
  4. #include <iomanip>
  5. using namespace std;
  6. double calculate_S(double x, double Y,int &n)
  7. {
  8.     double r = 1, S = 1;
  9.     n = 1;
  10.     while(abs(S-Y)>=0.0001) {
  11.         r *= x / (2 * n);
  12.         S += r * (n*n + 1);
  13.         n++;
  14.     }
  15.     return S;
  16. }
  17. double calcucalculate_Y(double x)
  18. {
  19.     return (x*x / 4 + x / 2 + 1)*exp(x / 2);
  20.  
  21. }
  22.  
  23. int main()
  24. {
  25.     setlocale(LC_ALL, "RUS");
  26.     int n;
  27.     double a, b, h, S, Y, r;
  28.     cout << "Введите a" << endl;
  29.     cin >> a;
  30.     cout << "Введите b" << endl;
  31.     cin >> b;
  32.     cout << "Введите h" << endl;
  33.     cin >> h;
  34.    
  35.     for (double x = a; x <= b; x += h) {
  36.         Y = calcucalculate_Y(x);
  37.         S = calculate_S(x, Y, n);
  38.         cout << setw(10) << "s=" << S << setw(10) << "y=" << Y << setw(10) << "s-y=" << abs(S - Y) <<setw(15)<<"n=" <<n<< endl;
  39.     }
  40.     system("pause");
  41.     return 0;
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement