Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <math.h>
- #include <iomanip>
- using namespace std;
- double calculate_S(double x, double Y,int &n)
- {
- double r = 1, S = 1;
- n = 1;
- while(abs(S-Y)>=0.0001) {
- r *= x / (2 * n);
- S += r * (n*n + 1);
- n++;
- }
- return S;
- }
- double calcucalculate_Y(double x)
- {
- return (x*x / 4 + x / 2 + 1)*exp(x / 2);
- }
- int main()
- {
- setlocale(LC_ALL, "RUS");
- int n;
- double a, b, h, S, Y, r;
- cout << "Введите a" << endl;
- cin >> a;
- cout << "Введите b" << endl;
- cin >> b;
- cout << "Введите h" << endl;
- cin >> h;
- for (double x = a; x <= b; x += h) {
- Y = calcucalculate_Y(x);
- S = calculate_S(x, Y, n);
- cout << setw(10) << "s=" << S << setw(10) << "y=" << Y << setw(10) << "s-y=" << abs(S - Y) <<setw(15)<<"n=" <<n<< endl;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement