Created
May 6, 2014 19:03
-
-
Save enapupe/c23405684654757ec807 to your computer and use it in GitHub Desktop.
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> | |
int main(){ | |
int max=3, i=0, j=0, k=0, l=max; | |
int x[max], y[max], z[max+max]; | |
printf("Digite os valores para o array X\n"); | |
for(i=0; i<max; i++){ | |
scanf("%d", &x[i]); | |
} | |
printf("Array X: "); | |
for(i=0; i<max; i++){ | |
printf("%d ", x[i]); | |
} | |
printf("\n"); | |
printf("Digite os valores para o array Y\n"); | |
for(i=0; i<max; i++){ | |
scanf("%d", &y[i]); | |
} | |
printf("Array Y: "); | |
for(i=0; i<max; i++){ | |
printf("%d ", y[i]); | |
} | |
printf("\n"); | |
//copia x para z | |
for(i=0; i<max; i++){ | |
z[k++]=x[i]; | |
} | |
//copiar o array x para o array z | |
//comparar o array y com o array z, elementos diferentes são copiados | |
//loop y inteiro | |
for(i=0; i<max; i++){ | |
k = 0; | |
//loop array Z inteiro e compara com x[i] | |
for(j=0; j<max; j++){ | |
//compara se x é igual alguma posição em Z | |
if(y[i] == x[j]){ | |
//se for igual alguma posicao, seta K = 1 | |
k = 1; | |
} | |
} | |
//caso k senha sido marcado como 1, não copia para z | |
if(k != 1){ | |
z[l] = y[i]; | |
l++; | |
} | |
} | |
//imprimir o array z | |
printf("Array Z: "); | |
for(i=0; i<(max+max); i++){ | |
printf("%d ", z[i]); | |
} | |
printf("\n"); | |
//system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment