#include <stdio.h>
#include <stdbool.h>
void PrintVetor(int conjunto[], int tamanho) {
for (int i
= 0; i
< tamanho
; i
++) printf(" %d", conjunto
[i
]); }
bool Existe(int x, int uniao[], int tamanho) {
for (int i = 0; i < tamanho; i++) if (uniao[i] == x) return true;
return false;
}
int main() {
int tamanho;
printf("Qual o tamanho dos conjuntos?\n"); int conjA[tamanho];
int conjB[tamanho];
int uniao[tamanho * 2];
printf("Preencha o Conjunto A\n"); for (int i = 0; i < tamanho; i++) {
uniao[i] = conjA[i];
}
printf("Preencha o Conjunto B\n"); for (int i
= 0; i
< tamanho
; i
++) scanf("%d", &conjB
[i
]); PrintVetor(conjA, tamanho);
PrintVetor(conjB, tamanho);
for (int i = 0, k = tamanho; i < tamanho; i++, k++) if (!Existe(conjB[i], uniao, k)) uniao[k] = conjB[i];
PrintVetor(uniao, tamanho * 2);
}
//https://pt.stackoverflow.com/q/343764/101
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRib29sLmg+Cgp2b2lkIFByaW50VmV0b3IoaW50IGNvbmp1bnRvW10sIGludCB0YW1hbmhvKSB7CglwcmludGYoIlsiKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgdGFtYW5obzsgaSsrKSBwcmludGYoIiAlZCIsIGNvbmp1bnRvW2ldKTsKICAgIHByaW50ZigiIF1cbiIpOwp9Cgpib29sIEV4aXN0ZShpbnQgeCwgaW50IHVuaWFvW10sIGludCB0YW1hbmhvKSB7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IHRhbWFuaG87IGkrKykgaWYgKHVuaWFvW2ldID09IHgpIHJldHVybiB0cnVlOwogICAgcmV0dXJuIGZhbHNlOyAKfQoKaW50IG1haW4oKSB7CiAgICBpbnQgdGFtYW5obzsKICAgIHByaW50ZigiUXVhbCBvIHRhbWFuaG8gZG9zIGNvbmp1bnRvcz9cbiIpOwogICAgc2NhbmYoIiVpIiwgJnRhbWFuaG8pOwogICAgaW50IGNvbmpBW3RhbW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