Question: Make a program that reads two vectors of 10 elements. Create a vector that is the union between the 2 previous vectors, that is, that contains the numbers of the two vectors. It should not contain repeated numbers.
#include <stdio.h>
#include <stdlib.h>
int main() {
int vetorA[10];
int vetorB[10];
int vetorAB[20];
int ate = 0;
for(int i = 0; i < 10; i++){
printf("Digite um valor para o vetorA[%d]:", i);
scanf("%d",&vetorA[i]);
}
printf("\n");
for(int j = 0; j < 10; j++){
printf("Digite um valor para o vetorA[%d]:", j);
scanf("%d",&vetorB[j]);
}
printf("\n");
for(int k = 0; k < 10; k++){
vetorAB[k] = vetorA[k];
}
for(int v = 0; v < 10; v++){
int achou = 0;
for(int z = 0; z < 10; z++){
if(vetorB[v] == vetorA[z]){
achou = 1;
break;
}
}
if(achou == 0){
vetorAB[v+10] = vetorB[v];
ate = ate + 1;
}
}
for(int u = 0; u < 10 + ate; u++){
printf("%d ", vetorAB[u]);
}
printf("\n");
system("PAUSE");
return 0;
}
I wanted to do a union of vectors, the algorithm starts by putting the values of vectorA in the vectorAB and then I had to test the values of B and the equals do not put in the vector of the union someone from a help there