4
#include<stdio.h>
main(){
int vetoresIguais= 0;
int vetor[3] = {10,20,5};
int vetor1[3]= {20,50,15};
int i;
int j;
for(i = 0; i < 3; i++){
for(j = i; j < 3;j++){
if(vetor[i] == vetor1[i]){
vetoresIguais++;
}
}
}
printf("%d",vetoresIguais);
}
The result of this code is 0,why is it comparing the vector to only one position,how to solve so that compare all values and tell how many values are repeated regardless of the position be equal or not?
(Feel free to edit, never learned kk,I’m new around here)
because you also need to execute both commands
for
for vector 1, so that it looks in each of its elements. It would be better to put this in a Function, already learned how to do this?– Ricardo Pontual
When comparing the vectors, change the i of vector 1 by j, becoming vector 1[ j ]
– IanMoone