cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

We are working to address an issue with subscription email notifications. In the meantime, be sure to check your favorite boards for new topics.

Finding the number and the index of the biggest number in an array thats less than X

S00tt
1-Newbie

Finding the number and the index of the biggest number in an array thats less than X

Can anyone help me?

I've got an array of 10 accending numbers that go from from 1 to 3000. I want to find what the biggest number thats less than or equal to 2000. e.g. if the array was 1,10,27,200,422,1500,1999,2500,2950, 3000 I would want the number 1999 and its index (6).

Thanks

7 REPLIES 7

In the attached one method.

Regards. Alvaro.

Or another

regards

Andy

Thanks

MikeArmstrong
5-Regular Member
(To:S00tt)

Slightly different approach.

Mike

There are an issue -call it a bug- after reading better the post. Attached finds the closer and the closer by the left to a number in a vector.

Regards. Alvaro.

MikeArmstrong
5-Regular Member
(To:AlvaroDíaz)

There are an issue -call it a bug- after reading better the post.

I'm not sure what your getting at?

Is it because I slightly modified Alan's function? All I was trying to do was to show a different way to iterate through the vector.

Mike

Alan's function and your modification it's ok. What is not is my first post: it searches for the closser in the vector, the title of the original post talk about the biggest but actually wanted result is the closser but by the left. What I modify was my first post, adding the requested search. But Alan implementation, and yours, are ok too.

Regards. Alvaro.

Top Tags