The cohomology of projective schemes can be computed by resolving the structure sheaf by twists of $\mathcal O_{\mathbb P^n}$. In the case of hypersurfaces, the resolution is especially nice, and the cohomology can be found by writing long exact sequences.
In your example, we have an exact sequence
$$
0 \to \mathcal O_{\mathbb P^ n}(-d) \to \mathcal O_{\mathbb P} \to \mathcal O_X \to 0
$$
where the left map is multiplication by $f$. Then one can take cohomology of this to compute $H^i(X,\mathcal O_X)$. We get
$$
...\to H^{i}(\mathcal O_{\mathbb P}(-d)) \to H^i(\mathcal O_{\mathbb P}) \to H^i(\mathcal O_X) \to H^{i+1}(\mathcal O_{\mathbb P}(-d)) \to ...
$$
If $0 < i < n$, then $H^i(\mathcal O_{\mathbb P}(l))=0$, so we get $H^i(\mathcal O_X(k))=0$ for $0 < i < n-1$. It remains to compute $H^0(\mathcal O_{X}(k))$ and $H^{n-1}(\mathcal O_X(k))$.
We have
$$
0 \to H^0(\mathcal O_{\mathbb P}) \to H^0(\mathcal O_{X}) \to 0
$$
so $H^0(\mathcal O_{X})=1$. But twisting will give
$$
0 \to H^0(\mathcal O_{\mathbb P}(-d+k)) \to H^0(\mathcal O_{\mathbb P}(k)) \to H^0(\mathcal O_X(k)) \to 0
$$
So for $k \geq d$, we get that $H^0(\mathcal O_X(k))$ is a difference of binomial coefficients. For $k < d$, we have $H^0(\mathcal O_X(k)) \simeq H^0(\mathcal O_{\mathbb P}(k))$.
To compute the top cohomology, just reverse the previous argument (in fancy language: use Serre duality on $\mathbb P^n$ and the adjunction formula on $X$).
In general, if $X$ is defined by more than one equation, you will have to split the resolution of $\mathcal O_X$ into short exact sequences and do more work. But it all follows from the cohomology of $\mathbb P^n$ and the fact that $h^0(\mathcal O_{\mathbb P}(d))=\binom{n+d}{d}$.