C47 Answer
/* Puzzle C47 -- check that an array has at least one
| element -N for each element N
|
| Return the count of the number of elements missing a match,
| zero or more. If one the value zero is in the array, it must
| be matched with a second zero.
|
| Note that an array might have more than one -N for a particular N.
*/
int posNegMatch( int arr[], int size )
{
int j, k ;
int target, found;
int missingCount = 0;
/* each element j should have a match */
for ( j=0; j<size; j++ )
{
target = -arr[j];
found = 0;
/* the match can be anywhere in the array, except at j */
/* (this is so a zero will not match itself */
for ( k=0; k<size && !found; k++ )
{
if ( k != j && arr[k] == target ) found = 1;
}
/* if no match was found increment the count */
if ( !found ) missingCount++ ;
}
return missingCount ;
}