|
-
February 21st, 2010, 10:14 PM
#1
Easy - Find the closest number
How do I find the number in a loop that is the closest to another given number.
For example: I have a simple loop that prints the numbers on the console. While for loop is working I want to find the number that is closest to 20.
I believe I have to use abs() in my loop to find the absolute value of the number and then subtract this number by 20, the smallest number is the closest. Is that right? But how do I compare the abs() value each time in the loop? Thanks for the answers.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|