-
Notifications
You must be signed in to change notification settings - Fork 0
/
Identity.c
62 lines (55 loc) · 1.09 KB
/
Identity.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
// C Program to check if a given matrix is an identity matrix
#include <stdio.h>
int main()
{
int a[10][10];
int i = 0, j = 0, row = 0, col = 0;
printf ("Enter the order of the matrix (mxn):\n");
printf ("where m = number of rows; and\n");
printf ("where n = number of columns\n");
scanf ("%d %d", &row, &col);
int flag = 0;
printf ("Enter the elements of the matrix\n");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
scanf ("%d", &a[i][j]);
}
}
printf("MATRIX is \n");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
printf("%3d", a[i][j]);
}
printf("\n");
}
// Equality condition
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
if (i == j && a[i][j] != 1)
{
flag = -1;
break;
}
else if (i != j && a[i][j] != 0)
{
flag = -1;
break;
}
}
}
if (flag == 0)
{
printf ("It is an IDENTITY MATRIX\n");
}
else
{
printf ("It is NOT an identity matrix\n");
}
return 0;
}