You are basically moving through your array from beginning to end want to zero out all of the current indexes multiples, right?
So at i = 5, you want to cross out 10, 15, 20 etc, starting at the NEXT multiple, so in this case 10.
So you start at 2*i and go in steps of i.
Look at your inner loop for j and think about this.
Tip: You can skip one iteration by using the keyword continue, like this:
1 2 3 4 5 6 7 8 9
|
for(int i = 0; i < 6; i++)
{
if(i == 3)
{
continue;
}
cout << i << ", ";
}
// Output: 0, 1, 2, 4, 5,
|
You can use this to check if you have already zeroed out the current array[i], and skip to the next iteration, otherwise your second loop would go in steps of 0 and give you an infinite loop.
I found a solution but since it's your homework you should be the one to figure it out ;)
For my solution I filled the array first with all the numbers starting at index 2, since otherwise it would be hard to distinguish between values that you have already set to 0 or were initialized to 0 in the first place. (At least thats what I think).
Hopefully I didn't give you too much information and ruin the exercise for you.