M
M
mirik20032020-11-19 16:14:39
C++ / C#
mirik2003, 2020-11-19 16:14:39

Can you please write the product of the sums in C++?

5fb66f4978ca7073727939.png
xs how, wrote, but does not give the correct value

for (int i = 0; i <= n-1; i++)
      {
        for (int j = 1; j <= n; j++)
        {
          sum += (x - i + j) * (x - i + j) * (x - i + j);
        }
        y *= sum;
                        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2020-11-19
@mirik2003

You need to initialize the accumulator variables before the loops: Before the loop over i, you need to assign y = 1. Before the loop over j, you need to assign sum = 0.
Otherwise, you accumulate the sum for all different i in sum. And y is generally unclear what value it has before multiplication.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question