Advertisement
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"
- 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 x, double f, double fk, double e, double xi, int i) {
- 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)));
- f += t;
- if (abs(f - fk) < e) {
- return f;
- }
- else {
- return receq(x, f, fk, e, t, i + 1);
- }
- }
- void main()
- {
- double e;
- cout << "Input accuracy of calculation" << endl;
- cin >> e;
- double x;
- cout << "Input point of equation" << endl;
- cin >> x;
- double k, t;
- k = x * sin(x) - exp(pow(x, 2) * -1) + 1;
- double r;
- double xf1 = pow(x, 2) * ((1.0 / fact(1)) + (1.0 / fact(1)));
- r = receq(x, xf1, k, e, xf1, 2);
- cout.precision(15);
- cout << "k = " << k << endl;
- cout << "r = " << r << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement