-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatEquality.c
81 lines (71 loc) · 2.06 KB
/
MatEquality.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// C Program to accept two matrices and check if they are equal
#include <stdio.h>
#include <stdlib.h>
void main()
{
int a[10][10], b[10][10];
int i, j, row1, column1, row2, column2, flag = 1;
printf("Enter the order of the matrix A \n");
scanf("%d %d", &row1, &column1);
printf("Enter the order of the matrix B \n");
scanf("%d %d", &row2, &column2);
printf("Enter the elements of matrix A \n");
for (i = 0; i < row1; i++)
{
for (j = 0; j < column1; j++)
{
scanf("%d", &a[i][j]);
}
}
printf("Enter the elements of matrix B \n");
for (i = 0; i < row2; i++)
{
for (j = 0; j < column2; j++)
{
scanf("%d", &b[i][j]);
}
}
printf("MATRIX A is \n");
for (i = 0; i < row1; i++)
{
for (j = 0; j < column1; j++)
{
printf("%3d", a[i][j]);
}
printf("\n");
}
printf("MATRIX B is \n");
for (i = 0; i < row2; i++)
{
for (j = 0; j < column2; j++)
{
printf("%3d", b[i][j]);
}
printf("\n");
}
// Comparing two matrices for equality
if (row1 == row2 && column1 == column2)
{
printf("Matrices can be compared \n");
for (i = 0; i < row1; i++)
{
for (j = 0; j < column2; j++)
{
if (a[i][j] != b[i][j])
{
flag = 0;
break;
}
}
}
}
else
{
printf(" Cannot be compared\n");
exit(1);
}
if (flag == 1)
printf("Two matrices are equal \n");
else
printf("But, two matrices are not equal \n");
}