forked from Shubhamlmp/Programming-Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
55_Searching.cpp
61 lines (33 loc) · 780 Bytes
/
55_Searching.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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
//To read No of elements in array
int N;
cin>>N;
ll arr[N];
ll sum=0;
//Reading Array Elements
for(int i=0;i<N;i++)
cin>>arr[i];
//Reading Element To be searched
ll target;
cin>>target;
int flag=0; //To find out whether element was in the array or not
//flag==0 represents not Present
// Findig if target Element Exist Or Not
for(int i=0;i<N;i++)
{
if(arr[i]==target)
{
//Target Element found
cout<<i<<"\n";
flag=1;
break;
}
}
//Target Element Not Found
if(flag==0)
cout<<-1<<"\n";
return 0;
}