Skip to content

Commit edda491

Browse files
authored
Print whether matrices are equal or not
1 parent f5bb0c8 commit edda491

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

2D Arrays/equal_matrices.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* C Program to Check Two Matrices are Equal or Not */
2+
3+
#include<stdio.h>
4+
5+
int main()
6+
{
7+
int i, j, rows, columns, a[10][10], b[10][10], isEqual;
8+
9+
printf("\n Please Enter Number of rows and columns : ");
10+
scanf("%d %d", &i, &j);
11+
12+
printf("\n Please Enter the First Matrix Elements\n");
13+
for(rows = 0; rows < i; rows++)
14+
{
15+
for(columns = 0;columns < j;columns++)
16+
{
17+
scanf("%d", &a[rows][columns]);
18+
}
19+
}
20+
21+
printf("\n Please Enter the Second Matrix Elements\n");
22+
for(rows = 0; rows < i; rows++)
23+
{
24+
for(columns = 0;columns < j;columns++)
25+
{
26+
scanf("%d", &b[rows][columns]);
27+
}
28+
}
29+
isEqual = 1;
30+
31+
for(rows = 0; rows < i; rows++)
32+
{
33+
for(columns = 0;columns < j;columns++)
34+
{
35+
if(a[rows][columns] != b[rows][columns])
36+
{
37+
isEqual = 0;
38+
break;
39+
}
40+
}
41+
}
42+
if(isEqual == 1)
43+
{
44+
printf("\n Matrix a is Equal to Matrix b");
45+
}
46+
else
47+
{
48+
printf("\n Matrix a is Not Equal to Matrix b");
49+
}
50+
return 0;
51+
}

0 commit comments

Comments
 (0)