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 * x * (i + 1) * fact(i - 1) / (i * fact(i));
- 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;
- k = x * exp(-x) - exp(-x) + 1;
- double r;
- r = receq(x, 0, k, e, -1, 1);
- cout.precision(15);
- cout << "k = " << k << endl;
- cout << "r = " << r << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement