C#. I need help about Multiply elements of loop!

Ex:(int b = 1; b < 5; b++)

How to have(write) :

Multiply each other elements in loop like : 1234 And " b * ( each element of loop)" like : 1(1+2+3+4) …Pls :slight_smile: I’m a beginer

I am not sure I really understand the question… but if the following answer is wrong, could you please clarify?

From what I understand, you are trying to have a loop that multiplies the sum of every index the loop will handle. So if you have:

for (int i = 1; i<5; i++)
{
    ...
}

you will want to get:

  • result of 1(1+2+3+4) for i=1
  • result of 2(1+2+3+4) for i=2
  • result of 3(1+2+3+4) for i =3
  • result of 4(1+2+3+4) for i = 4

If this is right, then this is how you can do it:

int b = 5;
int c = 0;
for (int i = 1; i<b; i++)
{
    c += i;
}
for (int i = 1; i<b; i++)
{
    print(i*c);
}

If, however, you are not trying to get a result but an expression ( “1(1+2+3+4)” instead of 10 ) then this is how you would do it:

int b = 5;
string c = "1";
for (int i = 2; i<b; i++)
    {
        c+= "+" + i;
    }
for (int i = 1; i<b; i++)
{
    print( i + "(" + c + ")" );
}

Hope this helps :slight_smile: