-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathIdentityMatrix.cpp
More file actions
66 lines (57 loc) · 1.21 KB
/
IdentityMatrix.cpp
File metadata and controls
66 lines (57 loc) · 1.21 KB
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
#include <iostream>
using namespace std;
int main()
{
int row, col;
cout << "Enter number of rows:";
cin >> row;
cout << "Enter number of columns:";
cin >> col;
int** a = new int* [row];
for (int i = 0; i < row; i++)
a[i] = new int[col];
cout << "Enter numbers in array:" << endl;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
cin >> a[i][j];
}
cout << "Entered array:" << endl;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
cout << a[i][j];
cout << endl;
}
int diag = 1;
int nonDiag = 1;
for (int i = 0; i < row; i++)
{
if (a[i][i] != 1)
diag = 0;
}
for (int i = 0; i < row - 1; i++)
{
for (int j = i + 1; j < col; j++)
{
if (a[i][j] != 0)
nonDiag = 0;
}
}
for (int i = 1; i < row; i++)
{
for (int j = 0; j < i; j++)
{
if (a[i][j] != 0)
nonDiag = 0;
}
}
if (diag && nonDiag)
cout << "Identity matrix" << endl;
else
cout << "Not an Identity matrix" << endl;
for (int i = 0; i < row; i++)
delete[] a[i];
delete[]a;
a = NULL;
}