STDIO Developer

20 bundles
1 file3 months ago
1

Linear Search

1234567891011121314151617
void LinearSearch(int arr[], int numberOfElements, int key) { int index = 0; bool isKeyFound = false; for (index; index < numberOfElements; index++) { if(arr[index] == key) { printf("%d is found at index %d\n", key, index); isKeyFound = true; } } if (index == numberOfElements && isKeyFound == false) printf("There is no %d in array.\n", key); }