### Program 129:To compare 2 Matrices

Program 126:

```#include<stdio.h>
main()
{
int i,j,rows_1,col_1,rows_2,col_2,flag=1;
printf("Enter number of rows and columns of matrix 1\n");
scanf("%d %d",&rows_1,&col_1);
printf("Enter number of rows and columns of matrix 2\n");
scanf("%d %d",&rows_2,&col_2);

int a1[rows_1][col_1],a2[rows_2][col_2];

if(rows_1==rows_2&&col_1==col_2)
{
//Taking input for 1st matrix
printf("Enter Matrix 1\n");
for(i=0;i<rows_1;i++)
{
for(j=0;j<col_1;j++)
{
scanf("%d",&a1[i][j]);
}
}
//Taking input for 2nd matrix
printf("Enter Matrix 2\n");
for(i=0;i<rows_2;i++)
{
for(j=0;j<col_2;j++)
{
scanf("%d",&a2[i][j]);
}
}

//Printing given matrices
printf("Matrix 1  is\n");
for(i=0;i<rows_1;i++)
{
for(j=0;j<col_1;j++)
{
printf("%d\t",a1[i][j]);

}
printf("\n");
}

printf("Matrix 2  is\n");
for(i=0;i<rows_2;i++)
{
for(j=0;j<col_2;j++)
{
printf("%d\t",a2[i][j]);
}
printf("\n");
}
//Comparing of matrix
for(i=0;i<rows_1;i++)
{
for(j=0;j<col_1;j++)
{
if(a1[i][j]!=a2[i][j])
{
flag=0;
}
}
}

if(flag==1)
{
printf("Both matrices are equal\n");
}
else
{
printf("Both matrices are not equal\n");
}

}
else
{
printf("Matrices Can not be compared\n");
}

}```
Explanation:

//Coming Soon

Output:

After 1st run:

After 2nd run:

After 3rd run:

 Donate Buy me a coffee \$2.00 USD Buy me a burger \$5.00 USD Buy me a pizza \$10.00 USD
 Compiler Used by me C-Free 5.0(Recommended) Other Compilers Code Blocks(Recommended) Online Compilers Ideone(Remember to give input before executing online where ever necessary)