I am having trouble interpreting how to write this fragment?
sum<--0
for i from 1 to n
sum <-- sum -1
for j from 1 to i
sum <-- sum + 2
Doing homework and I'm stuck (Fragments)
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Michal HabalcikRank #902 · 2.3K reputationPosted Jan 14, 2015, 8:37 PM EST
int sum = 0;
int n = ???;
for (int i=1; i <= n; i++)
{
sum -= 1;
for (int j=1; j<=i; j++)
sum += 2;
}Philip Harris36 reputationPosted Jan 20, 2015, 5:33 PM EST