Tuesday, March 15, 2016

C program to check whether a matrix exist in another matrix or not

#include<stdio.h>
void main()
{
 int const size =5;
 int i,j;
 int n=5;
 int a[size][size];
 int b[3][3]={{1,2,3},{6,7,8},{11,12,13}};
 int count;
 for(i=0;i<n;i++)
  {
   for(j=0;j<n;j++)
    {
     a[i][j]=n*i+j;
    }
  }
 int k,l;
 int o,p;
 for(i=0;i<n;i++)
  {
   for(j=0;j<n;j++)
    {
     count=0;
     for(o=0;o<3;o++)
      {
       for(p=0;p<3;p++)
{
if(((i+o)<n)&&((j+p)<n))
 {
 if(a[i+o][j+p]==b[o][p])
  {
   count++;
  }
 else
  {
   break;
  }
 }
else
 {
  break;
 }
}
      }
     if(count==9)
      {
       printf("Same pattern in the array found");
      }
    }
  }
}
output
Same pattern in the array found

No comments:

Post a Comment