Code: Select all
decl a;
a[1]=500;
a[2]=750;
a[3]=1000;
a[4]=2500;
a[5]=4500;
Code: Select all
decl b;
decl c;
b = 550;
c = getclosest(a, b); //should yeild a[1] or 500
b = 874;
c = getclosest(a, b); //should yeild a[2] or 750
Code: Select all
decl a;
a[1]=500;
a[2]=750;
a[3]=1000;
a[4]=2500;
a[5]=4500;
Code: Select all
decl b;
decl c;
b = 550;
c = getclosest(a, b); //should yeild a[1] or 500
b = 874;
c = getclosest(a, b); //should yeild a[2] or 750
Code: Select all
decl index;
decl closeness;
index=0;
closeness=abs(a[0]-b);
for (i=0; i<sizeof(a); i++)
if (abs(a[i]-b) < closeness)
{
closeness=abs(a[i]-b);
index=i;
}
return(a[index]);
Code: Select all
decl a;
a[500]=1;
a[750]=1;
a[1000]=1;
a[2500]=1;
a[4500]=1;