#include using namespace std; //Will return the index of the element if found //else will return -1 . int searchList(const int list[], int numElems, int value) { int index = 0; // Used as a subscript to search array int position = -1; // To record position of search value bool found = false; // Flag to indicate if the value was found while (index < numElems && !found) { if (list[index] == value) // If the value is found { found = true; // Set the flag position = index; // Record the value's subscript } index++; // Go to the next element } return position; // Return the position, or -1 } int main() { int arr1[] = { 2, 5, 3, 7, 1 } ; cout << searchList( arr1 , 5 , 3 ) << endl ; cout << searchList( arr1 , 5 , 8 ) << endl ; }