-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwo_dim_arrays_12.cpp
111 lines (104 loc) · 3.15 KB
/
two_dim_arrays_12.cpp
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int m, n;
cout << "Enter Row of Matrix : " << endl;
cin >> m;
cout << "Enter Column of Matrix : " << endl;
cin >> n;
int mat[m][n];
int sign[m][n];
int cofact[m][n];
int transpose[m][n];
if (m == n)
{
if (m == 1 && n == 1)
{
for (int i = 0; i < m; ++i)
{
for (int j = 0; j < n; ++j)
{
if (i == 0 && j == 0)
{
sign[i][j] = 1;
}
else if (i == 1 && j == 0)
{
sign[i][j] = -1;
}
else if ((i + j) % 2 == 0)
{
sign[i][j] = 1;
}
else
{
sign[i][j] = -1;
}
}
}
cout << " After Assigning signs for the square matrix it looks like" << endl;
cout << "\n";
for (int i = 0; i < m; ++i)
{
cout << "|";
for (int j = 0; j < n; j++)
{
cout << sign[i][j] << " ";
}
cout << "|";
cout << endl;
}
cout << endl;
cout
<< "Enter elements in the Matrix: " << endl;
cout << "\n";
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
cout << "mat[" << i << "][" << j << "] = ";
cin >> mat[i][j];
}
}
cout << "\n";
cout << " Representation of Matrix :(m x n) :" << endl;
cout << "\n";
for (int i = 0; i < m; i++)
{
cout << "|";
for (int j = 0; j < n; j++)
{
cout << mat[i][j] << " ";
}
cout << "|";
cout << endl;
}
cout << "\n";
cout << "Cofactor Matrix of (1x1) matrix :" << endl;
cofact[0][0] = (sign[0][0] * (mat[0][0]));
cout << "[" << cofact[0][0] << "]" << endl;
cout << " Transpose of Cofactor matrix in :(m x n) : initiating...." << endl;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
transpose[j][i] = cofact[i][j];
}
}
cout << " Representation of Transposed Cofactor Matrix :(m x n) :" << endl;
cout << "\n";
for (int i = 0; i < m; i++)
{
cout << "|";
for (int j = 0; j < n; j++)
{
cout << transpose[i][j] << " ";
}
cout << "|";
cout << endl;
}
}
}
}