Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int matrix[3][3] = {
  6.         {1, 2, 3},
  7.         {4, 5, 6},
  8.         {7, 8, 9}};
  9.  
  10.     int x = 0, y = 0, hasRepeated = 0;
  11.  
  12.     // Para cada valor vai ver se existe repetido na matriz
  13.     while (1)
  14.     {
  15.         // Percorre a matriz
  16.         for (int i = 0; i < 3; i++)
  17.         {
  18.             for (int j = 0; j < 3; j++)
  19.             {
  20.                 if (i != x || j != y)
  21.                 {
  22.                     if (matrix[i][j] == matrix[x][y])
  23.                     {
  24.                         hasRepeated = 1;
  25.                     }
  26.                 }
  27.             }
  28.         }
  29.  
  30.         y++;
  31.  
  32.         if (y == 3)
  33.         {
  34.             x++;
  35.             y = 0;
  36.  
  37.             if (x == 3)
  38.             {
  39.                 break;
  40.             }
  41.         }
  42.     }
  43.  
  44.     if (hasRepeated == 1)
  45.         printf("Tem numeros repetidos\n");
  46.     else
  47.         printf("Nao tem numeros repetidos\n");
  48.  
  49.     _getch();
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement