Complete the code to start the linear search loop from the first element.
for (int i = [1]; i < n; i++) { if (arr[i] == target) { return i; } }
The linear search starts checking from the first element, which is at index 0.
Complete the code to return -1 when the target is not found after the loop.
for (int i = 0; i < n; i++) { if (arr[i] == target) { return i; } } return [1];
Returning -1 indicates the target was not found in the array.
Fix the error in the loop condition to prevent out-of-bounds access.
for (int i = 0; i [1] n; i++) { if (arr[i] == target) { return i; } }
The loop must run while i is less than n to avoid accessing beyond the array.
Fill both blanks to complete the linear search function header and return type.
[1] linear_search(int arr[], int n, int target) { for (int i = 0; i < n; i++) { if (arr[i] == target) { return i; } } return [2]; }
The function returns an integer index, so return type is int and -1 indicates not found.
Fill all three blanks to complete the linear search call and print the result.
int result = linear_search([1], [2], [3]); printf("Index: %d\n", result);
Call linear_search with array name, size n, and the target value.
