D
D
doroshko2014-11-01 01:13:09
C++ / C#
doroshko, 2014-11-01 01:13:09

Why doesn't it calculate the complex construction k / (i*(i + 1)*(i + 2));?

Prompt why does not want to calculate the entire structure entirely?
We have to write the denominator in a separate variable.

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
  double step, result;
  double znam;
  int i, k;

  result = 0;
  i = 1;
  k = 1;
  do
  {
    //не вычисляет! step = 0, хотя должен 0,166667
    step = k / (i*(i + 1)*(i + 2));
    /*
    будет работать только так
    znam = i*(i + 1)*(i + 2);
    step = k / znam;
    */
    result += step;

    cout << i << " " << step << "\n";
    _getch();

    k = -k;
    i++;
  } while (i <= 5);

  cout << "Result: " << result;
  _getch();

  return 0;

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
neolink, 2014-11-01
@neolink

try
step = k / (double) (i*(i + 1)*(i + 2));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question