Kentoo

O#1

Jan 22nd, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include "math.h"
  4.  
  5. using namespace std;
  6.  
  7. int fact(int n) {
  8.     switch (n) {
  9.     case 0: return 1;
  10.     case 1: return 1;
  11.     default: {
  12.         int k = 1;
  13.         for (int i = 1; i <= n; i++)
  14.             k *= i;
  15.         return k;
  16.     }
  17.     }
  18. }
  19.  
  20. void main()
  21. {
  22.     double e;
  23.     cout << "Input accuracy of calculation" << endl;
  24.     cin >> e;
  25.     double x;
  26.     cout << "Input point of equation" << endl;
  27.     cin >> x;
  28.     double r, t = INT32_MAX;
  29.     int i = 1;
  30.     while (t > e) {
  31.         t = pow(-1, i + 1) * pow(x, 2 * i - 1) * (2 * i + 1 + x) / (fact(2 * i + 1) * 1.0);
  32.         r += t;
  33.         i++;
  34.     }
  35.     cout.precision(15);
  36.     cout << "r = " << r << endl;
  37.     system("pause");
  38. }
Advertisement
Add Comment
Please, Sign In to add comment