-3
Good afternoon! Personal someone knows how to invert elements of a vector, for example, type 12345 and the program returns 54321 I did it, but it didn’t work! [! [ [1]: https://i.stack.Imgur.com/mVkRM.png][1]][1]
#include <stdio.h>
int main(){
int vetOriginal[5], vetInvert[5];
int i, j;
for(i = 0; i < 5; i ++)
{
printf("Digite um número!\n");
scanf("%d", &vetOriginal[i]);
}
for(j = 0; j >= 4; j-- )
{
vetInvert[i] = vetOriginal[j];
printf("O vetor invertido é |\n %d", vetInvert[i]);
}
return 0;
}
Just change for(i = 0; j <= 4; i++, j--) for for (j = 0; j >= 4; j--)
– André
Welcome. Avoid posting code image, prefer to post the code itself in the question. It is easier to simulate, copy and paste, etc. Take a look and take a look here
– Ronaldo Araújo Alves
To invert do: for (i=0; i<5; i++) vetInvert[i] = vetOriginal[4-i];
– anonimo
@André Esse
for
that you suggested will never be executed, because ifj
starts at zero, the conditionj >= 4
is false and therefore never enters the loop: https://ideone.com/xCBbTP– hkotsubo