Help?

Im trying to compare multiple numbers with another.

Like 50 , 30 ,20 ,10 , 70 and find the closest one to 40.

Any idea on how i can do this?
Fill another array with abs(x-40), where x is the corresponding value in the first array. Then find the index of the smallest element in the second array and return the element in the first array, at that index. Example:
first = {50, 30, 20, 10, 70};
secon = {10, 10, 20, 30, 30};
smallest index = 0
closest value = first[smallest index] = 50
I would also like to add that the numbers are always changing and are usually random, it changes every 3secs and between those 3secs i need to get the closest number from all the numbers. Then do something when the number is found or send the output to a label in my form.
That doesn't change anything. Of course, you can do this without second array, not to waste memory, but I figured this would be easier.
Topic archived. No new replies allowed.