Easiest way to calculate amount of even numbers in given range

Posted by Fdr on Stack Overflow See other posts from Stack Overflow or by Fdr
Published on 2010-04-21T11:29:16Z Indexed on 2010/04/21 11:33 UTC
Read the original article Hit count: 187

Filed under:
|

What is the simplest way to calculate the amount of even numbers in a range of unsigned integers?

An example: if range is [0...4] then the answer is 3 (0,2,4)

I'm having hard time to think of any simple way. The only solution I came up involved couple of if-statements. Is there a simple line of code that can do this without if-statements or ternary operators?

© Stack Overflow or respective owner

Related posts about math

Related posts about c