Advertisement
Kentoo

A#1

Nov 27th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #define _USE_MATH_DEFINES
  4. #include "math.h"
  5. #include <windows.h>
  6.  
  7. using namespace std;
  8.  
  9. int fact(int n) {
  10.     switch (n) {
  11.     case 0: return 1;
  12.     case 1: return 1;
  13.     default: {
  14.         int k = 1;
  15.         for (int i = 1; i <= n; i++)
  16.             k *= i;
  17.         return k;
  18.     }
  19.     }
  20. }
  21.  
  22. double receq(double x, double f, double fk, double e, double xi, int i) {
  23.     double t = xi * pow(x, 4) * (4 * i - 2 - x) * fact(4 * i - 6) / ((4 * i - 6 - x) * fact(4 * i - 2));
  24.     f += t;
  25.     if (abs(f - fk)) {
  26.         return f;
  27.     }
  28.     else {
  29.         return receq(x, f, fk, e, t, i + 1);
  30.     }
  31. }
  32.  
  33. void main()
  34. {
  35.     SetConsoleCP(1251);
  36.     SetConsoleOutputCP(1251);
  37.     setlocale(LC_ALL, "rus");
  38.     double e;
  39.     cout << "Введите точность вычисления" << endl;
  40.     cin >> e;
  41.     double x;
  42.     cout << "Введите x" << endl;
  43.     cin >> x;
  44.     double k, t;
  45.     k = (sin(x) + cos(x) - exp(-x)) / 2.0;
  46.     double r;
  47.     r = receq(x, x*(2 - x) / 2.0, k, e, x*(2 - x) / 2.0, 2);
  48.     cout.precision(15);
  49.     cout << "k = " << k << endl;
  50.     cout << "r = " << r << endl;
  51.     cin >> r;
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement