Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #include <cmath>
- double x = 0.5;
- double fraction(int);
- double summa_Y();
- void monitor();
- /////////////////////////////////////////////
- int factorial(int i)
- {
- if (i == 0) return 1;
- else return i * factorial(i - 1);
- }
- /////////////////////////////////////////////
- int main()
- {
- setlocale(LC_ALL, "rus");
- int n;
- double S,
- eps = 0.0000001,
- P,
- Pon;
- while(x < 0.80)
- {
- Pon = fraction(1);
- monitor();
- for(n=2; n<=20; n++)
- {
- P = fraction(n);
- if(fabs(P) > eps) Pon += P;
- else
- {
- cout << n << " Моя сумма = "<<Pon+P<<" ";
- break;
- }
- }
- cout << "По проверке = "<< summa_Y() << endl;
- x+=0.05;
- }
- return 0;
- }
- ///////////////////////////////////////
- double fraction(int n) //
- {
- double f = (2*n*n + 1) * pow(x, 2*n); // numerator
- int n2 = factorial(2*n);
- return pow(-1, n-1) * f/n2;
- }
- ///////////////////////////////////////
- double summa_Y() //
- {
- double S = 1 + (x * sin(x))/2 + (pow(x, 2)/2 - 1)*cos(x);
- return S;
- }
- ///////////////////////////////////////
- void monitor() //
- {
- cout << "X = "; //<< cout.width(6) << x << "; ";
- cout << fixed;
- cout.precision(2);
- cout << x << "; ";
- cout.precision(11);
- // cout.unsetf (ios::fixed); // cout сброс флагов
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement