0
I need to reverse one vector and store in another one this way:
vector[5] = [1,2,3,4,5] < I will pass the values like this
inverse[5] = [5,4,3,2,1] < And accurate to invert values and position.
My code:
#include <stdio.h>
#include <stdlib.h>
int main(){
int cc[5], inverso[5]; //conta corrente
int i=0, k=5;
for(i; i < 5; i++){
printf("Numero da conta corrente: ", i); // Inserir valores
scanf(" %d", &cc[i]);
}
for(i=0; i < 5; i++){
for(k; k >= 0; k--){
if(inverso[i] == 0){
inverso[i] = cc[k-1]; //inverter o vetor e armazenar, -1 pois o ultimo numero armazenado está na posição 4 do vetor: cc[].
}else{
inverso[i] = cc[k];
}
}
}
for(i=0; i < 5; i++)
printf("%d", cc[i]); // Ver os valores armazenados
printf("\n");
for(i=0; i < 5; i++)
printf("%d", inverso[i]); //Verificar se for invertido
}
Dude, I used two for() because 1 is to traverse the 1st vector of 0:5 and another is to traverse the vector of 5:0, because I need to put in 1 position the value of the last position of the other vector, in case the code that you posted me the result: ex: vector 1: 12345 --- reversed: 55555
– WSS
Argh, error of typing:
[TAM_VET - i]
, nay[TAM_VET - 1]
. Edited the answer.– Wtrmute
I tested again, still error, I put: 1 2 3 4 5 - returns: 32765 5 4 3 2
– WSS