0
#include <iostream>
using namespace std;
int main(){
int myVector[] = {2,6,4,1,9,5,7,3,8,0};
int tamanhoVetor = sizeof(myVector)/sizeof(myVector[0]);
//Imprime
for (int i=0; i<tamanhoVetor-1; i++){
cout << myVector[i+1] << ", ";
}
return 0;
}
The expected would be:
6, 1, 5, 3, 0
but he returns:
6, 4, 1, 9, 5, 7, 3, 8, 0
I did not understand why it occurs this, I tried to do the same thing in Python, only that the same problem occurs. Probably the mistake is in my logic.
The variable sizeVetor is with the value 10, its starts at 0 and always prints the loop plus one, so you end up printing all the values of your vector, except for the first position.
– Daniel Mendes
If you want to skip numbers in the for, you can increase the increment of the same, increase for example two each cycle: for (int i=0; i<sizeVetor-1; i+=2)
– Daniel Mendes
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero