Advertisement
Lisaveta777

Find 2 equal els in 2D array

Jan 21st, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #define SIZE 10
  3. //https://otvet.mail.ru/question/212693092
  4.  
  5. int main(){
  6.     int i,j,ii,jj,arr[SIZE][SIZE];//={1,2,3,4,5,6,7,3,9};
  7.  
  8.     for(i=0;i<SIZE;i++)//populate array
  9.         for(j=0;j<SIZE;j++)
  10.         arr[i][j]=rand()%100;
  11.  
  12.     for(i=0;i<SIZE;i++)//print array
  13.     {
  14.         for(j=0;j<SIZE;j++)
  15.             printf("%d\t",arr[i][j]);
  16.         printf("\n");
  17.     }
  18.  
  19.     for(i=0;i<SIZE;i++)//search for equal array elements
  20.     {
  21.         for(j=0;j<SIZE;j++)
  22.         {
  23.             for(ii=0;ii<SIZE;ii++)
  24.             {
  25.                 for(jj=0;jj<SIZE;jj++)
  26.                 {
  27.                     if(arr[i][j]==arr[ii][jj]&&(i!=ii||j!=jj))
  28.                       printf("\n\n%d positions [%d][%d] and [%d][%d]\n",
  29.                              arr[i][j],i,j,ii,jj),
  30.                       i=j=ii=jj=SIZE;
  31.                 }
  32.             }
  33.         }
  34.     }
  35.  
  36.  
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement