Skip to content

Instantly share code, notes, and snippets.

@graifman
Created May 28, 2016 19:10
Show Gist options
  • Save graifman/19694a033895cfc25b2e48056e2abc68 to your computer and use it in GitHub Desktop.
Save graifman/19694a033895cfc25b2e48056e2abc68 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<n;j++){
if(vet1[i]==uniao[j]){
vdd++;
}
}
if(vdd<1){
printf("%d\n",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("%d\n",vet2[i]);
uniao[cont]=vet2[i];
cont++;
}
}
printf("\n\n\n");
for(j=0;j<cont;j++){
printf("%d ",uniao[j]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment