-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinearSearch2DArray
67 lines (62 loc) · 1.39 KB
/
LinearSearch2DArray
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
#include<iostream>
using namespace std;
bool isPresent(int arr[][4],int target,int row ,int col)
{
for(int row=0;row<3;row++)
{
for(int col=0;col<4;col++)
{
if(arr[row][col]==target)
{
return 1;
}
}
}
return 0;
}
int main()
{
//Create an 2-D Array
//int arr[3][4]={1,2,3,4,56,7,89,9,12,34,5,6};// Hardcode
//int arr[3][4]={{1,11,111,1111},{2,22,222,2222},{3,33,333,3333}};//-->row wise insertion
int arr[3][4];
int target;
//taking input-->row wise Input
cout<<"Enter an 2-D array"<<endl;
for(int row=0;row<3;row++)
{
for(int col=0;col<4;col++)
{
cin>>arr[row][col];
}
}
// //taking input-->coloumn wise Input
// cout<<"Enter an 2-D array"<<endl;
// for(int col=0;col<4;col++)
// {
// for(int row=0;row<3;row++)
// {
// cin>>arr[col][row];
// }
// }
//output
cout<<"Output of an 2-D array"<<endl;
for(int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
{
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
cout<<"Input The element you want to find in 2-D Array"<<endl;
cin>>target;
if(isPresent(arr,target,3,4))
{
cout<<"The element is present"<<endl;
}
else
{
cout<<"The element is not present"<<endl;
}
}