C42 Answer
/* Puzzle C42 -- find the first element of one array that is not in another
|
| The function returns the <strong>index</strong> of the first
| element of the first array that is not also in the second array.
| If all elements of the first array are also in the second array,
| return -1.
*/
int allPresent( int arrA[], int sizeA, int arrB[], int sizeB )
{
int j, k, current;
/* check the elements in the first array one by one */
for ( j=0; j<sizeA; j++ )
{
current = arrA[j];
/* find the first array's element in the second array */
k = 0;
while ( k<sizeB && current != arrB[k] )
k++ ;
/* return the index of the first element in arrA not in arrB */
if ( k==sizeB ) return j;
}
/* if all the elements in arrA are present in arrB, return -1 */
return -1;
}