Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #define _USE_MATH_DEFINES
- #include "math.h"
- #include <windows.h>
- using namespace std;
- int fact(int n) {
- switch (n) {
- case 0: return 1;
- case 1: return 1;
- default: {
- int k = 1;
- for (int i = 1; i <= n; i++)
- k *= i;
- return k;
- }
- }
- }
- double receq(double t, double f, double x, double e, double k, int i) {
- double t1 = t * pow(-1, i + 1)* pow(x, 2) * (fact(2 *(i - 1))) * (2*i + x) / (fact(2 * i) * (2*(i-1) + x));
- f += t1;
- if (abs(f - k) < e) {
- return f;
- }
- else {
- return receq(t1, f, x, e, k, i + 1);
- }
- }
- void main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- double e;
- cout << "Введите точность вычисления" << endl;
- cin >> e;
- double x;
- cout << "Введите x" << endl;
- cin >> x;
- double k, t;
- k = sin(x) - cos(x) + 1;
- double r;
- r = receq(1, 0, x, e, k, 1);
- cout.precision(15);
- cout << "k = " << k << endl;
- cout.precision(15);
- cout << "r = " << r << endl;
- cin >> r;
- }
Advertisement
Add Comment
Please, Sign In to add comment