Let's say we have two matrices A and B with the same dimensions. Is there any way to check if B is a permutation of A without any special functions or libraries in C ?
#include <stdio.h>
int intersection(int r[20][20],int f,int g,int m){
int i,j;
for (i=0;i<f;i++){
for (j=0;j<g;j++){
if (r[i][j]==m)
return 1;
}
}
return 0;
}
int main() {
int m[20][20],m1[20][20],a,b,i,j,l,k,counter=0;
scanf("%d %d", &a, &b);
for (i=0;i<a;i++){
for (j=0;j<b;j++){
scanf("%d",&m[i][j]);
}
}
for (i=0;i<a;i++){
for (j=0;j<b;j++){
scanf("%d",&m1[i][j]);
}
}
for (i=0;i<a;i++){
for (j=0;j<b;j++){
if (intersection(m1,a,b,m[i][j])==1)
counter++;
}
}
if (counter==a*b)
printf("YES");
}