0
Question: Make a program that reads two vectors of 10 elements. Create a vector that is the union between the two previous vectors, i.e., 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 join vectors , the algorithm starts by placing the values of the vector A in the vector B and then should test the values of B and the equals not to put in the vector of the union someone gives a help there
Mt thanks really worth it
– Antonio Lopes