Kentoo

A#1

Dec 17th, 2017
82
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. #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 t, double f, double x, double e, double k, int i) {
  23.     double t1 = t * pow(-1, i + 1)* pow(x, 2) * (fact(2 *(i - 1))) * (2*i + x) / (fact(2 * i) * (2*(i-1) + x));
  24.     f += t1;
  25.     if (abs(f - k) < e) {
  26.         return f;
  27.     }
  28.     else {
  29.         return receq(t1, f, x, e, k, i + 1);
  30.     }
  31. }
  32.  
  33. void main()
  34. {
  35.     SetConsoleCP(1251);
  36.     SetConsoleOutputCP(1251);
  37.     double e;
  38.     cout << "Введите точность вычисления" << endl;
  39.     cin >> e;
  40.     double x;
  41.     cout << "Введите x" << endl;
  42.     cin >> x;
  43.     double k, t;
  44.     k = sin(x) - cos(x) + 1;
  45.     double r;
  46.     r = receq(1, 0, x, e, k, 1);
  47.     cout.precision(15);
  48.     cout << "k = " << k << endl;
  49.     cout.precision(15);
  50.     cout << "r = " << r << endl;
  51.     cin >> r;
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment