Compare two matrix in C program by R4R Team

-Here we try to compare two matrix that they are equal or not.

program-

#include< stdio.h>
int main()
{
int a[10][10],b[10][10],r1,c1,r2,c2,i,j;
printf("Enter rows and columns in matrix_1\n");
scanf("%d%d",&r1,&c1);
printf("Enter %d numbers in matrix\n",r1*c1);
for(i=0;i< r1;i++)
{
for(j=0;j< c1;j++)
scanf("%d",&a[i][j]);
}
printf("Enter rows and columns in matrix_2\n");
scanf("%d%d",&r2,&c2);
printf("Enter %d numbers in matrix\n",r2*c2);
for(i=0;i< r2;i++)
{
for(j=0;j< c2;j++)
scanf("%d",&b[i][j]);
}
//Now compare both matrix
if(r1==r2 && c1==c2)
{
for(i=0;i< r1;i++)
{
for(j=0;j< c1;j++)
{
if(a[i]!=b[i])
{
printf("Both are different");
exit(0);
}
}
}
printf("Both are same");
}
else
{
printf("Both are different");
}
}


output-

Enter rows and columns in matrix_1
2 2
Enter 4 number in matrix
1 2 3 4
Enter rows and columns in matrix_2
2 2
Enter 4 number in matrix_2
1 2 3 4
Both are same

Enter rows and columns in matrix_1
2 2
Enter 4 number in matrix
1 2 3 4
Enter rows and columns in matrix_2
3 3
Enter 9 number in matrix
1 2 3 4 5 6 7 8 9
Both are Different




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!