-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab#02__Task#8.cpp
More file actions
35 lines (35 loc) · 897 Bytes
/
Copy pathLab#02__Task#8.cpp
File metadata and controls
35 lines (35 loc) · 897 Bytes
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
#include <iostream>
using namespace std;
void searchInMatrix(int matrix[4][4], int n) {
bool found = false;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (matrix[i][j] == n) {
cout << "Value found at row " << i << ", column " << j << endl;
found = true;
}
}
}
if (!found) {
cout << "Value not found in the matrix." << endl;
}
}
int main() {
int matrix[4][4] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16}
};
int n;
cout << "Enter the value to search for: ";
cin >> n;
cout << "Matrix:" << endl;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
cout << matrix[i][j] << " ";
}
}
searchInMatrix(matrix,n);
return 0;
}