-
Notifications
You must be signed in to change notification settings - Fork 13
/
matrixIdentity.cxx
80 lines (77 loc) · 1.19 KB
/
matrixIdentity.cxx
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
#include <stdio.h>
int main()
{
int mat1[3][3];
int mat2[3][3];
int mat3[3][3];
int i, j, k, l;
//input
printf("\nEnter the elements matrix 1 : ");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
printf("\nelement [%d : %d] = ", i + 1, j + 1);
scanf("%d", &mat1[i][j]);
}
}
printf("\nEnter the elements matrix 2 : ");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
printf("\nelement [%d : %d] = ", i + 1, j + 1);
scanf("%d", &mat2[i][j]);
}
}
//output
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
mat3[i][j] = 0;
}
}
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
for (k = 0; k < 3; k++)
{
mat3[i][j] = mat3[i][j] + mat1[i][k] * mat2[k][j];
}
}
}
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
if (mat3[i][j] == mat2[i][j])
{
l = 2;
}
else if (mat3[i][j] == mat1[i][j])
{
l = 1;
}
else if (mat3[i][j] != mat1[i][j] && mat3[i][j] != mat2[i][j])
{
l = 0;
break;
}
}
}
if (l == 2)
{
printf("\nmatrix 1 is identity");
}
else if (l == 1)
{
printf("\nmatrix 2 is identity");
}
else if (l == 0)
{
printf("\nNone of the above matrix is identity");
}
return 0;
}