Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- double x;
- cout << "Imput x from -1 to 1 \n";
- cin >> x;
- if (x <= -1 || x > 1) {
- cout << "Wrong number ";
- return 0;
- }
- int MaxIter = 1000;
- double eps = 1e-4;
- bool flag = true;
- double a = x;
- double s = a;
- for (int i = 1; fabs(a) > eps; i++) {
- a *= -x;
- s += a / (i + 1);
- if (i > MaxIter) {
- flag = false;
- break;
- }
- }
- if (flag) {
- cout << "s=" << s << "\tln(" << x << "+1)=" << log(x+1);
- } else {
- cout << "Series diverges";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement