Skip to content

Instantly share code, notes, and snippets.

Created Nov 10, 2020
What would you like to do?
using namespace std;
int linearSearch(int arr[], int n, int key){
for (int i = 0; i < n; i++){
if (arr[i] == key){
return i;
return -1;
int main(){
int n;
int arr[n];
for (int i = 0; i < n; i++){
int key;
cout<<linearSearch(arr, n, key)<<endl;
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment