#include using namespace std; int main() { int A[] = {1, 3, 7, 11, 15, 16, 22, 24, 25, 32, 35, 41, 42, 45, 47, 51}; int n = 16; for (int v=0; v < 55; v++) { // A is a *sorted* n-long array // v is a value to search for int p = 0 ; int r = n - 1 ; while (p != r){ int q = (p + r) / 2 ; if (v <= A[q]) { r = q ; } else { p = q +1 ; } } if (A[p] == v) { cout << v << " found" << endl; } } }