Skip to content

Commit

Permalink
find majority of nos in array
Browse files Browse the repository at this point in the history
  • Loading branch information
WaderManasi committed Sep 12, 2020
1 parent a954aa1 commit 45676d4
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Searching Algorithms/majority_element.cpp
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;
}

0 comments on commit 45676d4

Please sign in to comment.