forked from WaderManasi/Knowing-DataStructures-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a954aa1
commit 45676d4
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//Given an integer array and another integer element. | ||
//The task is to find if the given element is present in array or not. | ||
//solution: | ||
|
||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
int search(int arr[], int N, int X) | ||
{ | ||
for(int i=0;i<N;i++) | ||
{ | ||
if(arr[i]==X) | ||
return i; | ||
} | ||
return -1; | ||
} | ||
int main() | ||
{ | ||
int n,key; | ||
cin>>n; | ||
cin>>key; | ||
int arr[n]; | ||
for(int i=0;i<n;i++) | ||
cin>>arr[i]; | ||
cout<<search(arr,n,key)<<endl; | ||
return 0; | ||
} |