-
Notifications
You must be signed in to change notification settings - Fork 4
/
identitymatrixcheck.c
53 lines (50 loc) · 1.11 KB
/
identitymatrixcheck.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
//Check whether a matrix is identity matrix or not
#include <stdio.h>
void main()
{
int ord, i, j, f = 1;
printf("Enter the order of matirx:\n");
scanf("%d", &ord);
int a[ord][ord];
for (i = 0; i < ord; i++)
{
for (j = 0; j < ord; j++)
{
printf("Enter the [%d][%d] element:\n", i, j);
scanf("%d", &a[i][j]);
}
}
printf("The matrix you entered is:\n");
for (i = 0; i < ord; i++)
{
for (j = 0; j < ord; j++)
{
printf("\t%d", a[i][j]);
}
printf("\n");
}
for (i = 0; i < ord; i++)
{
for (j = 0; j < ord; j++)
{
if (i == j && a[i][j] != 1)
{
f = 0;
break;
}
if (i != j && a[i][j] != 0)
{
f = 0;
break;
}
}
}
if (f == 1)
{
printf("The matrix is an identity matrix");
}
if (f == 0)
{
printf("The matrix is not an identity matrix");
}
}