0
Generate and display sets A - B and B - A
A and B are both vectors with user-defined sizes
A -- allele 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 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]);
}
}
}
Thanks!!! Very good the code, only had to adapt it pq the values for vector A, are random values between -50 and 50. great code!!
– Iude Meneses
For nothing, any doubts post again
– rafael marques