Created
October 9, 2019 23:27
-
-
Save easleyschool/9ef7701503cc5194587a686b1013b445 to your computer and use it in GitHub Desktop.
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
/* | |
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