Example 1: the function search() returns 1 if query is present in the array data[] and 0 otherwise. No assumption is made about data order. Note how getinput() sets the variables when called in main(). #include using namespace std; int search(int data[], int size, int query) { for(a=0;a> size; for(int a=0; a> data[a]; return; } int main() { int data[100], size; getinput(data, size); // we assume nothing about the data order if (search(data,0,size-1,10)) cout << "The number 10 is present\n"; else cout << "The number 10 is not present\n"; return 0; } Example 2 : binsearch searches for q in the array a[] using the "binary search" algorithm. It assumes that the array a[] is sorted in increasing order. Note the recursive call in the program body. #include using namespace std; // binsearch assumes that the array is already sorted int binsearch(int a[], int low, int high, int q) { int mid = (low+high)/2; if (low==high) { // termination condition for the recursion if (q==a[low]) return 1; else return 0; } else if (q==a[mid]) { return 1; }else if (q>a[mid]) { return binsearch(a, mid, high, q); }else { // The only remaining possibility is q < a[mid]. return binsearch(a,low, mid, q); } } void getinput(int data[], int& size) { cout << "How many elements in the array ?\n"; cin >> size; for(int a=0; a> data[a]; return; } int main() { int data[100], size; getinput(data, size); // we assume the array is sorted in increasing order if (binsearch(data,0,size-1,10)) cout << "The number 10 is present\n"; else cout << "The number 10 is not present\n"; return 0; }