Skip to content

Instantly share code, notes, and snippets.

@zainulhasan
Created August 3, 2015 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zainulhasan/21a6881207ccdfeaa32a to your computer and use it in GitHub Desktop.
Save zainulhasan/21a6881207ccdfeaa32a to your computer and use it in GitHub Desktop.
/******************************
linearSearch.cpp
Auther:Syed Zain Ul hasan
*****************************/
#include <iostream>
using namespace std;
int linear_search(int arr[],int n,int item){
for(int i=0;i<n;i++)
if(arr[i]==item)
return i;
return -1;
}
int main() {
int arr[10]={5,8,79,9,87,98,7,2,5,4};
int item=87;
int index=linear_search(arr,10,item);
if(index!=-1)
cout<<item<<" Found at location : "<<index;
else
cout<<item<<" Not Found ";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment