What is the point of a global array (and size)? You certainly can't reuse your algorithm! The code is fine other than that. A more useful ( ie: reusable ) function however might be:
Code:
int duplicate (int array[], int objects, int index) {
int j = index + 1;
if (j <= objects)
{
while ( (array[index]!= array[j]) && (j <= objects) )
j++;
if (j > objects)
{
if (index < objects)
return duplicate(array, objects, index + 1);
else
return 0;
}
else return 1;
}
else return 0;
}
Of course, unless you are simply being told to use recursion here, it just doesn't make sense. ie:
Code:
int duplicate(int array[], int length)
{
int i, j;
for(i = 0; i < length-1; ++i)
{
for(j = i+1; j < length; ++j)
{
if(array[j] == array[i])
{
return 1;
}
}
}
return 0;
}