Generate and display sets A - B and B - A
A and B are both vectors with user-defined sizes
A - random values
B - user defined
For example: Vector A = (10), (5), (7), (8), (12)
vector B = (10), (8)
A-B
New Vector A = (5), (7), (12)
Code that I thought ***
int pertinencia(int vetor[], int tam, int ele) {
int i, pq = 0;
for (i = 0; i < tam; i++) {
if (vetor[i] == ele) {
return 1; //Este elemento pertence a o vetor
} else {
pq++;
}
}
if (pq == tam) {
return 0; //Este elemento nao pertence a o vetor
}
}
int main() {
int a[] = {
10,
5,
7,
8,
12
};
int b[] = {
10,
8
}, c[12];
int i;
for (i = 0; i < 2; i++) {
if (!pertinencia(a, 5, b[i])) {
printf("%d ", a[i]);
}
}
}