Question: I am trying to solve a programming problem where i encounter this pattern 1 1 2 2 3 3 4 4 . What is the formula for computing it for Nth term ?

Answer: 
Create a function that takes only integers

$$f : \mathbb Z \rightarrow \mathbb Z$$

and define it as

$$f(x) = \lceil x/2 \rceil$$

where $\lceil x \rceil$ is the ceiling function.

---

**Interesting fact:** You can define this function recursively where $$f(-1) = 0$$ $$ f(0)=0$$ $$f(n)=1+f(n-2)$$ 
While this would work, it would perform much worse than a function defined using the ceiling function. As Malloc explains, thanks to the power of modern computing, this is just as good as the function that explicitly uses the ceiling function. In fact, when compiled, they come out to the same thing!
Well? What answer do you *want*?

$a\_N \approx \frac N2$ but the exact value depends on whether $N$ is even or odd. 

The must obvious "binary" function that has two values depending on if the input is even or odd is $(-1)^N$ which is $1$ if $N$ is even and $-1$ if $N$ is odd.

So you have if $N = 2n-1; 2n$ if $N$ is odd; even$ then $a\_N = n = \frac N2; \frac {N+1}2$ if $N$ is even;odd.

Or $a\_N = \frac N2 + b\_N$ where $b\_N = 0$ if $N$ is even or $b\_N = \frac 12$ if $N$ is odd.

To solve for $b\_N$ note:

$(-1)^N = 1; -1$ if $N$ is even; odd.

$(-1)^N - 1 = 0; -2$

$\frac {(-1)^N -1}4 = 0, -\frac 12$.

$-\frac{(-1)^N -1}4 = 0; \frac 12$

So $a\_N = \frac N2 - \frac {(-1)^N -1}4$ is a solution if you *must* have a single line purely mathematical expression.

But *surely* if you are programming you are allowed to use conditional IF clauses and define a function based on whether the input is even or not.

So simply "if $N$ % $2== 0$ return $\frac N2$; else return $\frac {N+1}2$;" will do.