Hey everyone. I have a question about trying to delete successive elements from an array. For example im trying to delete every other element. Lets say my size is 10, so my elements are 0,1,2,...9. Heres what I want my output to look like:
0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 3 4 5 6 7 8 9
1 3 5 6 7 8 9
1 3 5 7 8 9
1 3 5 7 9
3 5 7 9
3 7 9
3 9
3
I know how to delete the 1st element but no luck otherwise.
here is my code:
int main()
{
const int max = 1000;
int num = 0, kill = 0;
std::cin >> num;
int x[max] = {0};
for (int i = 0; i < num; i++)
{
x[i] += i;
std::cout << x[i] << ' ';
}
std::cout << '\n';
for (int i = 0; i < num; i++)
{
if (x[i] == kill)
{
while (i < num)
{
x[i] = x[i + 1];
i++;
}
num--;
}
kill += 2;
}
for (int i = 0; i < num; i++)
{
std::cout << x[i] << ' ';
}
return 0;
}