-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray8.cpp
More file actions
180 lines (163 loc) · 2.93 KB
/
Copy pathArray8.cpp
File metadata and controls
180 lines (163 loc) · 2.93 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cmath>
using namespace std;
void LinearIndx(int matrix[8][8], int row, int col, int m, int n)
{
int B[(row * col) * ((row * col) + 1) / 2];
int i, j;
int x = 0;
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
B[x] = matrix[i][j];
++x;
}
}
cout << "Elements In Array" << endl;
for (i = 0; i < x; i++)
{
cout << B[i] << ", ";
}
cout << endl;
int y = 0;
for (int i = 0; i < x; ++i)
{
if (B[i] == matrix[m][n])
{
cout << "Index of"
<< " " << matrix[m][n] << " "
<< "In The Array Is"
<< " " << i << endl;
};
}
}
void InverseIndx(int matrix[3][3], int row, int col, int U)
{
int B[(row * col) * ((row * col) + 1) / 2];
int i, j;
int x = 0;
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
B[x] = matrix[i][j];
++x;
}
}
cout << "Elements In Array" << endl;
for (i = 0; i < x; i++)
{
cout << B[i] << ", ";
}
cout << endl;
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
if (matrix[i][j] == B[U])
{
cout << "Index of"
<< " " << B[U] << " "
<< "In The Matrix Is"
<< " "
<< "(" << i << "," << j << ")" << endl;
}
}
}
}
int main()
{
int k = 0;
int A[8][8];
int row = 8, col = 8;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
A[i][j] = rand() % 1000 + 1;
;
}
}
int size = row * col;
int B[size];
int C[10][10];
int i, j;
int x = 0;
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
if (i < j)
{
cout << " "
<< " ";
}
else
{
cout << A[i][j] << " ";
B[x] = A[i][j];
C[i][j] = B[x];
++x;
}
}
cout << endl;
}
cout << endl;
cout << "The first 20 values of the lower trinagular elements of A[8][8]:";
for (i = 0; i < 20; i++)
{
cout << B[i] << " ";
}
cout << endl;
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
if (A[i][j] == B[k] && k != 20)
{
cout << "Index of"
<< " " << B[k] << " "
<< "In The Matrix Is"
<< " "
<< "(" << i << "," << j << ")" << endl;
++k;
};
}
}
cout << endl;
cout << "The first 20 elements of B[] and their respective indices;" << endl;
for (i = 0; i < 20; i++)
{
cout << "Index of"
<< " " << B[i] << " "
<< "In The Array Is"
<< " " << i << endl;
}
cout << endl;
int h = 0;
int rowl = 10;
int coll = 10;
for (i = 0; i < rowl; i++)
{
for (j = 0; j < coll; j++)
{
C[i][j] = B[h++];
}
}
cout << endl;
cout << "The first 20 elements of C[][] and their respective indices;" << endl;
for (i = 0; i < 2; i++)
{
for (j = 0; j < 10; j++)
{
cout << "Index of"
<< " " << C[i][j] << " "
<< "In The Matrix Is"
<< " "
<< "(" << i << "," << j << ")" << endl;
}
}
}