Compute the definite integral
$$ \int^{\pi/2}_{0}\cos^{n}(x)\cos (nx)\,dx $$
where $n\in \mathbb{N}$.
My Attempt:
Using $\cos (x) = \frac{e^{ix}+e^{-ix}}{2}$, we get
$$ \begin{align} \int^{\pi/2}_{0}\cos^{n}(x)\cos (nx)\,dx&=\int_{0}^{\pi/2} \left(\frac{e^{ix}+e^{-ix}}{2}\right)^n\left(\frac{e^{inx}+e^{-inx}}{2}\right)\,dx\\ &= \frac{1}{2^n}\mathrm{Re}\left\{\int_{0}^{\pi/2} \left(e^{ix}+e^{-ix}\right)^n\cdot e^{inx}\,dx\right\}\\ &=\frac{1}{2^n}\mathrm{Re}\left\{\int_{0}^{\pi/2}\left(e^{2ix}+1\right)^n\,dx\right\} \end{align} $$
Letting $z=e^{4ix}$ gives us
$$ \begin{align} e^{4ix}dx &= \frac{1}{4i}dz\\ dx &= \frac{dz}{4iz} \end{align} $$
So the integral becomes
$$\frac{1}{4\cdot 2^n}\mathrm{Re}\left\{\int_{C}\left(\sqrt{z}+1\right)\cdot \frac{dz}{iz}\right\}$$
How can I complete the solution from here?
Your start is not bad, but you can get it simpler by using the evenness of $\cos$,
$$\int_0^{\pi/2} \cos^n x \cos (nx)\,dx = \frac12 \int_{-\pi/2}^{\pi/2} \cos^n x\cos (nx)\,dx.$$
Since the sine is an odd function, we can replace $\cos (nx)$ with $e^{inx}$:
$$\begin{align} \int_0^{\pi/2} \cos^n x \cos (nx)\,dx &= \frac12\int_{-\pi/2}^{\pi/2}\cos^n x \, e^{inx}\,dx\\ &= \frac{1}{2^{n+1}} \int_{-\pi/2}^{\pi/2} \left(e^{ix}+e^{-ix}\right)^n e^{inx}\,dx\\ &= \frac{1}{2^{n+1}} \int_{-\pi/2}^{\pi/2} \left(e^{2ix}+1\right)^n\,dx. \end{align}$$
Next we substitute $\varphi = 2x$ and get
$$ \int_0^{\pi/2} \cos^n x \cos (nx)\,dx = \frac{1}{2^{n+2}} \int_{-\pi}^\pi \left(e^{i\varphi}+1\right)^n\,d\varphi. $$
Now setting $z = e^{i\varphi}$ gets us a nice contour integral over the unit circle,
$$\begin{align} \int_0^{\pi/2} \cos^n x \cos (nx)\,dx &= \frac{1}{2^{n+2}} \int_{\lvert z\rvert = 1} (z+1)^n\,\frac{dz}{iz}\\ &= \frac{\pi}{2^{n+1}} \end{align}$$
by the Cauchy integral formula.