Let $f : \mathbb N \to \mathbb Z$ be defined by
$$ f(x) = \left\{\begin{array}{lr} \frac{n+1}{2}, & \text{if } n \text{ is odd}\\ \frac{-n}{2}, & \text{if } n \text{ is even}\\ \end{array}\right. $$
Here $\mathbb N$ denotes the set of natural numbers and $\mathbb Z$ denotes set of integers.
I have proved the injective part as true but the surjective part is coming out to be false (answer is true according to book). At first I made cases according to even/odd. Then I equated $f(n) = y$ so as to get value of $n$ for which there is a image '$y$' for $n$ (according to cases). But it turned out to be true for some values as domain of '$n$' is natural numbers whereas $y$ is integer. Is the approach correct?
For surjectivity, you need to ask yourself whether every $z \in \mathbb{Z}$ is the image of some $n \in \mathbb{N}$.
Scratch work: for $n$ odd, you have $f(n)=\tfrac{n+1}{2}$, which is clearly positive. How do you need to pick $n$ to get a fixed, positive $z$-value? $$\frac{n+1}{2} = z \iff n=2z-1$$ Note that for $z > 0$, $n=2z-1$ is odd so... Similar scratchwork for $n$ even, corresponding to the negative $z$-values. Concluding: