Artificial intelligent assistant

Finding final value of sum from double summation code fragment. sum = 0; inc = 0 for i from 1 to n for j from 1 to i sum = sum + inc inc = inc + 1 What does it mean when it is asking the "final value of sum" from above code fragment. Can someone give me some hints so that I can work on this exercise. Thank you in advance.

It means to find the value of 'sum' after the for loops have been executed.

EDIT: The following assumes both of the last code pieces are inside the inner loop.

First we find the number of times sum+inc is executed. This is

$$\sum\limits_{i=1}^n\sum\limits_{j=1}^i1=\sum\limits_{i=1}^ni=\frac{n(n+1)}{2}.$$

Define $\mathrm{Inc}(k)$ as the value of inc in the $k$-th execution of sum+inc. Then

$$\mathrm{FinalSum}=\sum_{k=1}^{n(n+1)/2}\mathrm{Inc}(k)$$

For each time sum+inc is executed is executed, inc increases by $1$ and it starts at $0$, but we only increment inc after we have added it to sum, so $\mathrm{Inc}(k)=k-1$. Hence $$\begin{align}\mathrm{FinalSum}&=\sum_{k=1}^{n(n+1)/2}\mathrm{Inc}(k) \\\&=\sum_{k=1}^{n(n+1)/2}k-1 \\\&=\sum_{k=0}^{n(n+1)/2-1}k \\\&=\frac{(n(n+1)/2-1)(n(n+1)/2)}{2} \\\&=\frac{1}{8}\left(n(n+1)-2\right)\left(n(n+1)\right) \\\&=\frac{1}{8}n(n+1)(n^2+n-2) \end{align}$$

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy e98ae57bc346ce6f3bb858b31c9c9fff