Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #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;
- }
- }
- }
- void main()
- {
- double e;
- cout << "Input accuracy of calculation" << endl;
- cin >> e;
- double x;
- cout << "Input point of equation" << endl;
- cin >> x;
- double r, t = INT32_MAX;
- int i = 1;
- while (t > e) {
- t = pow(-1, i + 1) * pow(x, 2 * i - 1) * (2 * i + 1 + x) / (fact(2 * i + 1) * 1.0);
- r += t;
- i++;
- }
- cout.precision(15);
- cout << "r = " << r << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment