Skip to content

Instantly share code, notes, and snippets.

@easleyschool
Created October 9, 2019 23:27
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 easleyschool/9ef7701503cc5194587a686b1013b445 to your computer and use it in GitHub Desktop.
Save easleyschool/9ef7701503cc5194587a686b1013b445 to your computer and use it in GitHub Desktop.
/*
below we have implemented a simple function
for linear search in C
- values[] => array with all the values
- target => value to be found
- n => total number of elements in the array
*/
int linearSearch(int values[], int target, int n)
{
for(int i = 0; i < n; i++)
{
if (values[i] == target)
{
return i;
}
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment