The statement follows:
Read two vectors of X and Y integers, each one with 5 elements (assume that the user does not report repeated elements). Calculate and show the resulting vectors in each case below:
Sum of X and Y: sum of each element of X with the element of the same position in Y;
Product between X and Y: multiplication of each element of X with the element of the same position in Y;
Difference between X and Y: all elements of X that do not exist in Y;
Intersection between X and Y: only the elements that appear in the two vectors;
Link between X and Y: all elements of X, and all elements of Y that are not in X.
code:
#include <stdio.h>
#include <locale.h>
#define TAM 5
int main(){
setlocale(LC_ALL,"Portuguese");
int x[TAM], y[TAM], dif[TAM], c, c2, c3, n=0, uniao[TAM*2], aux=0;
printf("Lendo o vetor X: \n");
for (c=0; c<TAM; c++){
scanf("%d", &x[c]);
}
printf("\n\nLendo o vetor Y: \n");
for (c=0; c<TAM; c++){
scanf("%d", &y[c]);
}
system("CLS");
printf("Soma entre X e Y:\n");
for (c=0; c<TAM; c++){
printf("%d\n", x[c] + y[c]);
}
printf("\n\nProduto entre X e Y:\n");
for (c=0; c<TAM; c++){
printf("%d\n", x[c] * y[c]);
}
printf("\n\nDiferenca ente X e Y:\n");
for(c=0; c<TAM; c++){
for(c2=0; c2<TAM; c2++){
if(x[c] == y[c2])
break;
}
if(c2==TAM){
for(c3=0; c3<n; c3++){
if(x[c] == dif[c])
break;
}
if(c3 == n)
dif[n++] = x[c];
}
}
for (c=0; c<n; c++){
printf("%d\n", dif[c]);
}
printf("\n\nIntersecção entre X e Y:\n");
for (c=0; c<TAM; c++){
for (c2=0; c2<TAM; c2++){
if (x[c] == y[c2]){
printf("%d\n", x[c]);
}
}
}
printf("\n\nUnião entre X e Y:\n");
}
I am not able to make the union without repeating elements .. can anyone help me? Thank you