I have written a logic to find out the intersection of two arrays. Please review my logic and guide me if my logical approach is not correct.
#include<stdio.h> void intersect(int a1[][2], int a2[][2],int row, int col) { int i = 0, j= 0, x = 0, y = 0; for(i = 0; i <row ; i++) { for(j = 0 ; j < col ; j++) { for(x = 0; x < row ; x++) { for(y = 0; y < col ; y++) { if(a1[i][j] == a2[x][y]) printf("%d\t",a1[i][j]); } } } } } int main() { int arr1[2][2]={{2,5},{6,8}}; int arr2[2][2]={{1,2},{8,8}}; row = (sizeof(arr1)/sizeof(arr1[0])); col = (sizeof(arr1[0])/sizeof(arr1[0][1])); intersect(arr1,arr2,row,col); }