I am trying to make an inversion of an array in the C
language.
For example: I have an array [1, 2, 3]
, I need to invert the numbers in the SAME array, giving an output like this: [3,2,1]
. I'm trying, but on reaching the second position of the array, it starts to mirror. Here is the code and thank you right away:
int main(int argc, char** argv) {
int x[4];
int i, j, aux;
for (i = 0; i <= 3; i++){
printf("\nEscreva um numero\n");
scanf("\n%d", & x[i]);
}
i = 0;
for (j = 3; j >= 0; j = j - 1){
aux = x[i];
x[i] = x[j];
x[j] = aux;
i++;
}
for (i = 0; i <= 3; i++){
printf("\n numero: %d\n", x[i]);
}
}