# Is there a trick to finding the number of odd numbers b/w two values?

I know you could find the number of even numbers (since they are a multiple of two). For example the number of even numbers between $11$ and $30$ will be $$n= \frac{28-12}{2} + 1 = 9$$

I wanted to know is there a similar way to find the number of odd numbers b/w two extremes?

You can use the exact formula. What is number of odd numbers between $11$ and $30$?

$$n = (29-13)/2 + 1 = 16/2 + 1 = 9$$

Let's list them out to make sure $: 13, 15, 17, 19, 21, 23, 25, 27, 29.$ There are $9$ of them, so that is correct. By the way, your formula was calculated wrong. $$n = (28-12)/2 + 1 = 16/2 + 1 = 8 + 1 = 9 (12, 14,16,18,20,22,24,26,28)$$

• Sidd's answer certainly gives you what you want, and if you understand the reasoning behind the formula for evens then you should be able to see why it works for odds too. But here's another way of thinking about it: Counting the number of odd numbers between 11 and 30 is the same as counting the number of even numbers between 12 and 31. Aug 6, 2012 at 5:40

Method 1:

If you can find the number of numbers, and you can find the number of even numbers, ....

Method 2:

The number of odd numbers between 11 and 30 is the same as the number of even numbers between 12 and 31.

• Ah, a breath of sanity ... Jul 8, 2016 at 5:58

use the A.P formula for finding the number of terms...say for no. of odd numbers between 1 and 11.... nth term= first term+(n-1)(common difference)......(*),where n=no. of terms,which we have set out to find in this case.

from (*) we have n= {(nth term-first term)/common difference}+1.....

For our problem, n= {(11-1)}/2}+1 =6

here common difference is 2 as an odd number occurs by adding 2 to the previous odd number etc.,

If you use the formula $(b-a)/2 + 1$, then for some case it would give wrong answer.

Say, $a = 2$ and $b = 4$, so there is only one ODD nmumber between 2 and 4 (inclusive), and that is 3.

By using the formula, we get $(4-2)/2 + 1 = 2$, that is wrong; if we consider a small alter here, we will calculate the difference like this:

$Diff = (b - a) /2 + X$

Here $X$ will be either 0 or 1 depending on whether any one of the variables (a or b) is odd or not. If $a \mod 2 = 1 \lor b \mod 2 =1$, then $X$ will be 1, otherwise 0.

You can use this formula which gives you the number of integers congruent to $${n}\pmod p$$ in the interval $$a$$ inclusive and $$b$$ inclusive :

$$S =\lfloor\frac{n-a}{p}\rfloor+\lfloor\frac{b-n}{p}\rfloor+1$$

So here, we get : $$\lfloor\frac{1-11}{2}\rfloor+\lfloor\frac{30-1}{2}\rfloor+1 = \lfloor-\frac{10}{2}\rfloor+\lfloor\frac{29}{2}\rfloor+1=-5+14+1=10$$

There is $$10$$ odd numbers between $$11$$ and $$30$$. If we disregard $$11$$, then there are $$9$$.

To get count of odd or even numbers between a range, follow the process as below:

Correct the Range to start and end with inclusive numbers as per question and then use following formula :

(m - n)/2 + 1 where m is greater than n

Example:

All Odd numbers between 21 - 61

correct the range to make it inclusive of the numbers which make the range to 23 - 59 use the formula:

(59 - 23)/2 + 1 => 19

All even numbers between 21 - 61

correct the range to make it inclusive of the numbers which make the range to 22 - 60 use the formula:

(60 - 22)/2 + 1 => 20

For Calculating Even and Odd where S= starting number and E= ending Number

No. Of even = m.floor((e-s)/2)+(-(e%2)+1)

No. Of Odd = m.ceil((e-s)/2)+(e%2)

The Problem What is the number of EVEN or ODD integers between two numbers n and m?

(where m>n)

Solution:

1. Recall the formula (m-n+1)/2
2. Calculate it.
3. See below for how to interpret: