-
Notifications
You must be signed in to change notification settings - Fork 0
/
2DarraySearch.cpp
60 lines (49 loc) · 1.02 KB
/
2DarraySearch.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
#include <iostream>
using namespace std;
int main()
{
int n, m;
cout << "Enter the number of rows and columns: ";
cin >> n >> m;
int A[n][m];
cout << "Enter the elements of the array:\n";
//Storing user input in the memory
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
cin >> A[i][j];
}
}
cout << "The elements of the array are:\n";
// printing array elements
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
cout << A[i][j] <<" ";
}
cout<<endl;
}
int x;
cin>>x;
bool flag=false;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(A[i][j]==x)
{
cout<<i<<" "<<j<<endl;
}
}
}
if(flag)
{
cout<<"Element is found"<<endl;
}
else{
cout<<"Element is not found"<<endl;
}
return 0;
}