#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int linearSearch( const int [], int, int ); // prototype
int main()
{
const int arraySize = 100;
int a[ arraySize ];
int searchKey = 28;
for ( int i = 0; i < arraySize; i++ )
a[ i ] = 2 * i;
int element = linearSearch( a, searchKey, arraySize );
cout << element << endl;
return 0;
}
int linearSearch( const int array[], int key, int sizeOfArray )
{
for ( int j = 0; j < sizeOfArray; j++ ){
if ( array[ j ] == key ){
return j;
}
}
return -1;
}
|