Skip to content

Instantly share code, notes, and snippets.

@PedroHLC
Forked from graifman/gist:19694a033895cfc25b2e48056e2abc68
Last active October 10, 2017 01:12
Show Gist options
  • Save PedroHLC/ac810ae06d4a00f9f69669bd780dfc67 to your computer and use it in GitHub Desktop.
Save PedroHLC/ac810ae06d4a00f9f69669bd780dfc67 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#define n 10
#include <time.h>
int main()
{
int vet1[n],vet2[n],uniao[n*2];
int i,j,vdd=0,max,cont=0;;
srand(time(NULL));
printf("Primeiro vetor:\n");
for(i=0;i<n;i++){
vet1[i]=rand()%11;
printf("%d\n",vet1[i]);
}
printf("\nSegundo vetor:\n");
for(i=0;i<n;i++){
vet2[i]=rand()%11;
printf("%d\n",vet2[i]);
}
printf("\nUniao:\n");
for(i=0;i<n;i++){
vdd=0;
for(j=0;j<cont;j++){
if(vet1[i]==uniao[j]) {
vdd++;
}
}
if(vdd<1){
printf("add 1x%d: %d\n",cont,vet1[i]);
uniao[cont]=vet1[i];
cont++;
}
}
for(i=0;i<n;i++){
vdd=0;
for(j=0;j<cont;j++) {
if(vet2[i]==uniao[j]){
vdd++;
}
}
if(vdd<1){
printf("add 2x%d: %d\n",cont,vet2[i]);
uniao[cont]=vet2[i];
cont++;
}
}
for(j=0;j<cont;j++)
printf(" %d", uniao[j]);
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment