#include // Provides cin, cout #include // Provides EXIT_SUCCESS, size_t void search(const int a[ ], size_t first, size_t size, int target, bool& found, size_t& location) // Precondition: The array segment starting at a[first] and containing size // elements is sorted from smallest to largest. { size_t middle; if (size == 0) found = false; else { middle = first + size/2; if (target == a[middle]) { location = middle; found = true; } else if (target < a[middle]) search(a, first, size/2, target, found, location); else search(a, middle+1, (size-1)/2, target, found, location); } } void main( ) { const size_t MANY = 10; int fibonacci[MANY] = { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 }; int target; bool found; size_t location; do { cout << "Please type an integer from 0 to 100: "; cin >> target; } while ((target < 0) || (target > 100)); search(fibonacci, 0, MANY, target, found, location); if (found) cout << target << " is a Fibonacci number at [" << location << "] in my array." << endl; else cout << target << " is not a Fibonacci number." << endl; }