C24 Answer


#include <stdio.h>
#include <stdlib.h>

/* Puzzle C24 -- linear search: look for the first element x in an array, 
|                starting at an index 
|
|  Return the first index at which x is found, or -1 if not found.
|
*/
int linearSearchMid( int arr[], int size, int x, int start )
{
  int j;
  
  for ( j=start; j < size; j++ )
  {
    if ( arr[j] == x ) return j;
  }
  
  return -1;
}


Comments: What happens if the starting index is less than zero? The above program will probably crash.