Trigonometric integral using residue complex analysis. There is this problem where I need to proof the following statement: $$\int_{0}^{\pi}\cos^{2n}\theta d\theta = \pi\frac{(2n)!}{2^{2n}(n!)^2}$$ First I used the fact that the function is ever so I can divide by $2$ and integrate over $(0,2\pi)$. Then I made the substituition: $$z=e^{i\theta}\,dz=iz\,d\theta\quad\text{then}\quad\cos\theta=\frac{z^2+1}{2z},$$ letting $C$ be the unitary circle:$$\frac{1}{i2^{2n+1}}\oint_{C}\frac{(z^2+1)^{2n}}{z^{2n+1}}dz.$$ Now since there is a pole at $z=0$, I chose to just use the Cauchy-formula for $(2n)$ rank pole, taking the numerator $(z^2+1)^{2n}$ for $f(z)$: $$\oint_{C}\frac{(z^2+1)^{2n}}{z^{2n+1}}dz=\frac{2\pi i}{(2n)!}\frac{d^{2n}}{dz^{2n}}f(0).$$ The $2n$ derivatives leaves me $(2n)!2^{2n}$ and then inserting this to the total: $$\int_{0}^{\pi}\cos^{2n}\theta\,d\theta = \pi.$$ I tried the residue theorem, but it is just what i have been doing above. What is wrong here? The problem or my calculations?

Your problem is with formula:
$$\oint_{C}\underbrace{\frac{(z^2+1)^{2n}}{z^{2n+1}}}_{f(z)}dz=\frac{2\pi i }{(2n)!}\left(\frac{d^{2n}}{dz^{2n}}f\right)_{|z=0}.$$
which should be:
$$\oint_{C}\frac{(z^2+1)^{2n}}{z^{2n+1}}dz=\frac{2\pi i }{(2n)!} \left(\frac{d^{2n}}{dz^{2n}}z^{2n+1}f\right)_{|z=0}.$$
due to formula of residue in a pole $c$ with order $n$:
$$\displaystyle \operatorname {Res} (f,c)={\frac {1}{(n-1)!}}\lim _{z\to c}{\frac {d^{n-1}}{dz^{n-1}}}\left((z-c)^{n}f(z)\right).$$
