Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #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(x, 2) * fact(2 * (i - 1)) / fact(2 * i);
- 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 = (exp(x) + exp(-x)) / 2.0;
- double r;
- r = receq(1, 1, x, e, k, 1);
- cout.precision(15);
- cout << "k = " << fixed << k << endl;
- cout << "r = " << fixed << r << endl;
- cout << "Абсолютная погрешность = " << fixed << k - r << endl;
- cout << "Относительная погрешность = " << fixed << ((k - r) / k) * 100 << "%" << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement