Hey guys started programming in C few weeks ago learning about algothiritms, just wondering how would you make my code more simple its just a binary search function. But the only thing is you must keep the arguments the same, thanks in advance.
bool search(int value, int values[], int n)
{
int min = values[0];
int max = values[n-1];
int average = (min + max) / 2;
if(average == value)
{
return true;
}
while (average > value)
{
max = average - 1;
average = (min + max) / 2;
}
while (average < value)
{
min = average + 1;
average = (min + max) / 2;
}
if (max < min)
{
return false;
}
if (average == value) {
printf("%i\n", average);
return true;
}
else
{
return false;
}
}