#include<stdio.h>
int IsEqual(int [][100],int,int, int[][100],int,int);
main()
{
int m1[100][100],m2[100][100],r1,r2,c1,c2,i,j;
printf("\nEnter row and column number of the first matrix=");
scanf("%d%d",&r1,&c1);
printf("\nEnter the elements of the first matrix\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&m1[i][j]);
}
}
printf("\nThe first matrix\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%6d",m1[i][j]);
}
printf("\n");
}
printf("\nEnter row and column number of the second matrix=");
scanf("%d%d",&r2,&c2);
printf("\nEnter the elements of the first matrix\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&m2[i][j]);
}
}
printf("\nThe second matrix\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("%6d",m2[i][j]);
}
printf("\n");
}
if(IsEqual(m1,r1,c1,m2,r2,c2)==1)
printf("\nThe matrices are equal");
else
printf("\nThe matrices are not equal");
}
int IsEqual(int a[][100],int r1,int c1, int b[][100],int r2,int c2)
{
int i,j;
if(r1!=r2 || c1!=c2)
return 0;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
if(a[i][j]!=b[i][j])
{
return 0;
}
}
}
return 1;
}
int IsEqual(int [][100],int,int, int[][100],int,int);
main()
{
int m1[100][100],m2[100][100],r1,r2,c1,c2,i,j;
printf("\nEnter row and column number of the first matrix=");
scanf("%d%d",&r1,&c1);
printf("\nEnter the elements of the first matrix\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&m1[i][j]);
}
}
printf("\nThe first matrix\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%6d",m1[i][j]);
}
printf("\n");
}
printf("\nEnter row and column number of the second matrix=");
scanf("%d%d",&r2,&c2);
printf("\nEnter the elements of the first matrix\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&m2[i][j]);
}
}
printf("\nThe second matrix\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("%6d",m2[i][j]);
}
printf("\n");
}
if(IsEqual(m1,r1,c1,m2,r2,c2)==1)
printf("\nThe matrices are equal");
else
printf("\nThe matrices are not equal");
}
int IsEqual(int a[][100],int r1,int c1, int b[][100],int r2,int c2)
{
int i,j;
if(r1!=r2 || c1!=c2)
return 0;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
if(a[i][j]!=b[i][j])
{
return 0;
}
}
}
return 1;
}
No comments:
Post a Comment