1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include <iostream>
using namespace std;
const int ARRAY_SIZE = 10;
bool isMember(int [], int, int);
int main()
{
// Create an array with some values in it.
int numbers[ARRAY_SIZE] = {2, 4, 6, 8, 10, 12, 14, 16 ,18, 20 };
// Search for the values 0 through 20 in the array.
for (int x = 0; x <= 20; x++)
{
if (isMember(numbers, x, ARRAY_SIZE))
cout << x << " is found in the array.\n";
else
cout << x << " is not found in the array.\n";
}
return 0;
}
bool isMember(int numbers[], int x, int ARRAY_SIZE)
{
if (numbers[ARRAY_SIZE] == numbers[ARRAY_SIZE])
return false;
if (numbers[ARRAY_SIZE]== x)
{
return true;
}
else
{
return isMember(numbers + 1,x, ARRAY_SIZE);
}
}
|