Contact Learn C
Copy Program Share Program

Program 292: Check Whether Both Matrices are Equal or not

Program 292: Check Whether Both Matrices are Equal or not
 
#include<stdio.h>
main()
{
 int i,j,row1,row2,column1,column2,flag;
 printf("Enter row1\n");
 scanf("%d",&row1);
 printf("Enter column 1\n");
 scanf("%d",&column1);
 printf("Enter row2\n");
 scanf("%d",&row2);
 printf("Enter column 2\n");
 scanf("%d",&column2);
  int a[row1][column1],b[row2][column2];
  if(row1==row2 && column1==column2)
  {
   flag=1;
   printf("Enter Matrix A\n");
      for(i=0;i<row1;i++)
       {
      for(j=0;j<column1;j++)
        scanf("%d",&a[i][j]);
      }
      printf("Enter Matrix B\n");
      for(i=0;i<row2;i++)
       {
      for(j=0;j<column2;j++)
        scanf("%d",&b[i][j]);
      }
      
      for(i=0;i<row1;i++)
      {
       for(j=0;j<column1;j++)
       {
        if(a[i][j]!=b[i][j])
        {
         flag=0;
         break;
        }
       }
      }
      if(flag==1)
     {
      printf("Both Matrices are equal\n");
     }
     else
     {
      printf("Matrices are not Equal\n");
     }
  }
  else
  {
   printf("Not Possible to Compare as Rows and Columns are Not equal\n");
  }     
 
}

Explanation:

//Coming Soon...

Output:
Check Whether Both Matrices are Equal or not

Check Whether Both Matrices are Equal or not

Check Whether Both Matrices are Equal or not






 

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide