A
A
Alexey2020-11-12 12:27:08
Mathematics
Alexey, 2020-11-12 12:27:08

How to calculate this example (the sum of the series) * (the product of the series) + why does it display such a result?

I came across such an example, I 5facff54e40ca846129915.jpeg
looked at how and what works, I made just such a program.

#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{
  setlocale(LC_ALL, "rus");
  double x,s=1,i=1, sumar=0, proizr=1,k=3,n;
  cout << "Введите x= ";
  cin >> x;
  cout << "Введите n = ";
  cin >> n;
  for (k; k <= n; k++) {
    sumar += (pow(-2, k - 1)) / ((k - 5)*pow(x,k));
  }
  for (i; i < k + 7; i++) {
    proizr *= ((pow(i, 3) - 27) / (i - 7));
  }
  s = sumar * proizr;
  cout <<fixed << setprecision(4)<< "s = " << s;
}

It does not give any errors, there are no warnings either, after calculations "s" displays as -nan ( ind ).
I would be glad if you point out an error, or tell me how best to solve such a problem.
PS otherwise everything is in order, calculated by debugging, the second cycle does not work
for (i; i < k + 7; i++) {
    proizr *= ((pow(i, 3) - 27) / (i - 7));
  }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AVKor, 2020-11-12
@resolut1123

No way. I didn’t read the whole code, but NaN should turn out there (the denominator of the fraction turns to zero). The task was given by some idiot.

W
Wataru, 2020-11-12
@wataru

You have an error in that you consider the product once after looping over k. At that moment, k after the loop is equal to n. Those. as if you have n instead of k in the formula as the boundary for the product.
You need to count proizr inside the loop over k and multiply each term by it. (don't forget to initialize proizr with one).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question