Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define MAX 10
- /* 7. Leia dois conjuntos de 10 números cada. Exiba a
- intersecção dos conjuntos, ou seja, os números que são
- repetidos nos dois conjuntos. */
- int main()
- {
- int conjunto1[MAX],conjunto2[MAX],i,j,cont=0;
- printf("\n Preencha o conjunto 1: ");
- for(i=0;i<MAX;i++)
- {
- printf("\n Digite um valor: ");
- scanf("%d",&conjunto1[i]);
- }
- printf("\n Preencha o conjunto 2: ");
- for(i=0;i<MAX;i++)
- {
- printf("\n Digite um valor: ");
- scanf("%d",&conjunto2[i]);
- }
- printf("\n Interseccao: ");
- for(i=0;i<MAX;i++)
- {
- for(j=0;j<MAX;j++)
- {
- if(conjunto1[i]==conjunto2[j])
- {
- cont++;
- if(cont==1)
- {
- printf("\n %d",conjunto1[i]);
- }
- conjunto2[j]=-1;
- }
- cont=0;
- }
- }
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement