Advertisement
Kentoo

E#4

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