example:
set of numbers:1,3,8,5,78
a=6
so the nearest number is 6!
i remember that there was a function like this but i cant remeber any help!
6i have a set numbers and i want to see which number is nearest to "a"
example:
set of numbers:1,3,8,5,78
a=6
so the nearest number is 6!
i remember that there was a function like this but i cant remeber any help! Rolling Eyes
Code: Select all
int i=0;
int j=arraysize;
int m=(i+j)/2;
int n=tab[m];
while(i!=j)
{
if(tab[m]==a) return a;
if(abs(tab[m]-a) < abs(n-a))
{
n=tab[m];
}
if(tab[m]<a)
{
i=m;
}
else
{
j=m;
}
m=(i+j)/2;
}
return n;