Calculate the sum of an infinite series using user functions. Create two types of programs using external (global) variables and variables passed to and from a function. 
x = 0.56 Accuracy = 2 * (10 to the power of -5)
Calculate the sum of an infinite series using user functions. Create two types of programs using external (global) variables and variables passed to and from a function. 
x = 0.56 Accuracy = 2 * (10 to the power of -5)
It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
Well, since I am accused of being heartless here :)
int main() { const double eps = 2e-5; const double x = 0.56; double fact = 2; double ex = exp(x+1); double term = x*x*log(1+x)/(fact + ex); double sum = term; for(int i = 2; fabs(term) > eps; ++i) { term *= -x*log(i+x)*(fact + ex)/log(i-1+x); sum += term /= (fact *= i+1) + (ex *= 2.718281828); } cout << sum << endl; } double calcSum(double x) { int i = 1; double ch = pow(-1, i + 1) * ((pow(x, i + 1) * log(i + x)) / (fact(i + 1) + pow(M_E, i + x))); double sum = 0; while (fabs(ch) > EPS) { sum += ch; i++; ch = pow(-1, i + 1) * ((pow(x, i + 1) * log(i + x)) / (fact(i + 1) + pow(M_E, i + x))); } return sum; } Implemented, but it seems to me that the result is not correct since only one step is performed in the cycle. Who can, check whether all the rules.
#include <cstdio> #include <cmath> #define EPS (2 * pow(10, -5)) int fact(int x) { return !x || x == 1 ? 1 : fact(x - 1) * x; } double getEx(int i, double x) { return pow(-1, i + 1) * ((pow(x, i + 1) * log(i + x)) / (fact(i + 1) + pow(M_E, i + x))); } double calcSum(double x) { int i = 1; double ch = getEx(i, x); double sum = 0; while (fabs(ch) > EPS) { sum += ch; ch = getEx(++i, x); } return sum; } int main() { double x = 0.56; double sum = calcSum(x); printf("Summa ryada sostavila %.6lf", sum); return 0; } while in a stop condition, not a continuation. - IgorSource: https://ru.stackoverflow.com/questions/755223/
All Articles
pow(-1, i + 1)I would deploy a solution like yours ... Or for calculating the factorial for each member ... - Harry