Advertisement
weldisalves

Lista 04 - exercício 07

Jun 18th, 2013
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #define MAX 10
  3. /* 7. Leia dois conjuntos de 10 números cada. Exiba a
  4. intersecção dos conjuntos, ou seja, os números que são
  5.  repetidos nos dois conjuntos. */
  6.  
  7. int main()
  8. {
  9.     int conjunto1[MAX],conjunto2[MAX],i,j,cont=0;
  10.  
  11.     printf("\n Preencha o conjunto 1: ");
  12.     for(i=0;i<MAX;i++)
  13.     {
  14.         printf("\n Digite um valor: ");
  15.         scanf("%d",&conjunto1[i]);
  16.     }
  17.  
  18.     printf("\n Preencha o conjunto 2: ");
  19.     for(i=0;i<MAX;i++)
  20.     {
  21.         printf("\n Digite um valor: ");
  22.         scanf("%d",&conjunto2[i]);
  23.     }
  24.     printf("\n Interseccao: ");
  25.  
  26.     for(i=0;i<MAX;i++)
  27.     {
  28.         for(j=0;j<MAX;j++)
  29.         {
  30.             if(conjunto1[i]==conjunto2[j])
  31.             {
  32.                 cont++;
  33.                 if(cont==1)
  34.                 {
  35.                     printf("\n %d",conjunto1[i]);
  36.                 }
  37.                 conjunto2[j]=-1;
  38.             }
  39.             cont=0;
  40.         }
  41.     }
  42.     getch();
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement