#define NOT_FOUND -1 /* this is not a legal index, so it is safe. */ int linear_search(int data[], int target, int n) { /* Use parameter n as local counter variable. * Initial value is one larger than largest index. */ while ( --n >= 0 ) if ( data[n] == target ) break; /* found target */ return n; /* If while-condition failed, this is NOT_FOUND; * if loop terminated by break, this is the target index. */ }