我在互联网上查找了此类任务的示例代码,但它不适合。
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
setlocale(LC_ALL, "ru");
double x, E = 0.001, summ = 0.0;
int n = 0;
cout << "Введите -1 < x < 1: ";
cin >> x;
double formula = (pow(x, 2 * n + 1)) / (2 * n + 1);
while (formula >= E)
{
if (n % 2 == 0)
{
summ += formula;
}
else
{
summ -= formula;
}
n += 1;
formula = (pow(x, 2 * n + 1)) / (2 * n + 1);
}
n += 1;
cout << "Число членов ряда: " << n << endl;
cout << "Сумма бесконечного ряда с точность 0.001: " << summ;
}
我希望得到快速的帮助,最重要的是,解释这个问题的解决方案:)

好吧,这是一个带有递归的选项。不是最好的,远不是最有效的,但是有递归:)