//
// example of recursion:
//
// 	function to check for element in array
//
// main (test) program prompts for input
//
#include <iostream.h>

// precondition:  n >= 0, and array a has at least n elements
// postcondition:  returns true if x is in a[0] .. a[n-1], false
//	otherwise
bool inArray(const int x, const int n, const int a[]);

// ---- main program ----

int main()
{
	const int size = 10;
	int nums[size];
	int n;
	char prompt[] = "enter a number to search for, or control-D " 
		"to end:\n";
	cout << "enter " << size << " numbers for array:\n";
	for (int i = 0; i < size; i++)
		cin >> nums[i];
	cout << prompt;
	while (cin >> n)
	{
		if (inArray(n, size, nums))
			cout << "found\n";
		else
			cout << "not found\n";
		cout << prompt;
	}
	return 0 ;
}

// ---- function definition ----

bool inArray(const int x, const int n, const int a[])
{
	if (n == 0)
		return false;
	else
		return (x == a[n-1]) || inArray(x, n-1, a);
}