-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex030.c
65 lines (56 loc) · 1.36 KB
/
ex030.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* ex030.c
*
* Criado em: 11 de jun de 2023
* Autor: Renato Gomes de Sousa
*
* https://github.com/RenatoEngineer
*/
#include <stdio.h>
int main(){
int vetor1[10];
int vetor2[10];
int vetorIntersecao[10];
int tamanhoIntersecao = 0;
char ordinal = 176;
printf("Elementos do Primeiro Vetor (10 Elementos):\n");
for (int i = 0; i < 10; i ++){
printf("Digite o %d%c Elemento: ", i + 1, ordinal);
fflush(stdout);
scanf("%d", &vetor1[i]);
}
printf("\nElementos do Segundo Vetor (10 Elementos):\n");
for (int i = 0; i < 10; i ++){
printf("Digite o %d%c Elemento: ", i + 1, ordinal);
fflush(stdout);
scanf("%d", &vetor2[i]);
}
//Verificando a Intersecao entre os Vetores
for (int i = 0; i < 10; i ++){
for (int j = 0; j < 10; j ++){
if (vetor1[i] == vetor2[j]){
//Verifica se o Elemento ja esta no Vetor de Intersecao
int repetido = 0;
for (int k = 0; k < tamanhoIntersecao; k ++){
if (vetorIntersecao[k] == vetor1[i]){
repetido = 1;
break;
}
}
if (!repetido){
vetorIntersecao[tamanhoIntersecao] = vetor1[i];
tamanhoIntersecao ++;
}
}
}
}
if(tamanhoIntersecao == 0){
printf("\nNao ha Intersecao entre os Vetores 1 e 2!\n");
}else{
printf("\nElementos da Intersecao:\n");
for (int i = 0; i < tamanhoIntersecao; i ++){
printf("%d\n", vetorIntersecao[i]);
}
}
return 0;
}