Forked from graifman/gist:19694a033895cfc25b2e48056e2abc68
Last active
October 10, 2017 01:12
-
-
Save PedroHLC/ac810ae06d4a00f9f69669bd780dfc67 to your computer and use it in GitHub Desktop.
Natasha -> União vetores # forked from https://gist.github.com/graifman/19694a033895cfc25b2e48056e2abc68
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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