-
Notifications
You must be signed in to change notification settings - Fork 0
/
Identity Matrix Checker
72 lines (54 loc) · 1.13 KB
/
Identity Matrix Checker
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
/*
Humza KHawar
Lab Task
Comparing Matrix with identity matrix
*/
#include<stdio.h>
void main()
{
//initialization of array
int matrix1[10][10] = { 0 }, size, flag = 0;
//inputing size
printf("\n Enter he size of the Square Matrix: ");
scanf("%d", &size);
//inputing elements of matrix
printf("\nMatrix 1");
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
printf("\nEnter Number [%d] [%d]: ", 1+i,1+ j);
scanf("%d", &matrix1[i][j]);
}
}
//printing the matrix
printf("\nYour Matrix 1:\n");
for(int i = 0; i < size; i++)
{
printf("\n |");
for (int j = 0; j < size; j++)
{
printf(" %3d ", matrix1[i][j]);
}
printf(" |");
}
//checking each element of matrix
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
if ( ((matrix1[i][j] != 1) && (i==j)) || ((matrix1[i][j] != 0) && (i != j)))
{
flag = 1; //flag is increased to 1 if any element is not equal to identity matrix
}
}
}
if (flag ==1)
{
printf("\n\nMatrix is NOT Identiy Matrix\n\n");
}
else
{
printf("\n\nMatrix is Identiy Matrix\n\n");
}
}