Is it possible to calculate $\int_{0}^{\pi}(a+\cos{\theta})^nd\theta$, where $a$ is a nonzero integer? I have tried to answer by taking change the variable $\theta$ to $\theta/2$, so the integration is now over unit circle, then I have taken $z=e^{i\theta}$. Now I tried to use residue formula for integration, but I failed.
 A: This method solves the integral when $n\in\mathbb{N}$ and $a\in\mathbb{C}$.
By using binomial expansion the integral becomes
$$\int_0^\pi\sum_{k=0}^n\left( \binom{n}{k} a^{n-k} \cos^k{(\theta)} \right)d\theta=\sum_{k=0}^n\left( \binom{n}{k} a^{n-k}\int_0^\pi \cos^k{(\theta)} d\theta\right)$$
Now we can use the Beta function in order to find the latter integral
$$B(x,y)=\frac{(x-1)!(y-1)!}{(x+y-1)!}=2\int_0^\frac\pi2 \sin^{2x-1}{(\theta)}\cos^{2y-1}{(\theta)}d\theta$$
$$\int_0^\pi \cos^k{(\theta)} d\theta=\begin{cases}
0&k\,\text{ odd}\\
B\left(\frac12,\frac{k+1}2\right)&\text{otherwise}
\end{cases}$$
Now we just have to simplify
$$\begin{align}
B\left(\frac12,\frac{k+1}2\right)
&=\frac{(-\frac12)!(\frac{k}{2}-\frac12)!}{(\frac{k}2)!}\\
&=\frac{(-\frac12)!(\frac{k}{2}-\frac12)(\frac{k}{2}-\frac32)\dots(\frac32)(\frac12)(-\frac12)!}{(\frac{k}2)!}\\
&=\frac{((-\frac12)!)^2(k-1)(k-3)\dots(3)(1)}{2^{\frac{k}2}(\frac{k}2)!}\\
&=\frac{((-\frac12)!)^2(k-1)(k-3)\dots(3)(1)}{2^{\frac{k}2}(\frac{k}2)(\frac{k}2-1)\dots(2)(1)}\\
&=\frac{((-\frac12)!)^2(k-1)(k-3)\dots(3)(1)}{(k)(k-2)\dots(4)(2)}\\
&=\frac{((-\frac12)!)^2(k-1)!!}{k!!}\\
\end{align}$$
Where $k!!$ denotes the Double factorial. The value of $(\frac12)!$ is well known as
$$\left(\frac12\right)!=\frac12\left(-\frac12\right)!=\frac{\sqrt{\pi}}2\implies\left(-\frac12\right)!=\sqrt{\pi}$$
Hence our integral is finally given by
$$\int_0^\pi \cos^k{(\theta)} d\theta=\begin{cases}
0&k\,\text{ odd}\\
\frac{(k-1)!!}{k!!}\pi&\text{otherwise}
\end{cases}$$
This gives the solution to the original integral as
$$\boxed{\large{\int_{0}^{\pi}(a+\cos{\theta})^nd\theta=\pi a^n\sum_{k=0}^{\lfloor\frac{n}2\rfloor} \left(\binom{n}{2k} \frac{(2k-1)!!}{a^{2k}(2k)!!}\right)}}$$
A: Winther notes in the comments that integration by parts gives
$$
(n+1)I_{n+1} = (2n+1)a I_n - n(a^2-1)I_{n-1}
$$
This is suspiciously close to the recursion relation for the Legendre Polynomials,
$$
(n+1)P_{n+1}(x) = (2n+1)x P_n(x) - nP_{n-1}(x).
$$
To get it into the same form, divide through by $(a^2-1)^{(n+1)/2}$
$$
(n+1)\left[\frac{I_{n+1}}{(a^2-1)^{(n+1)/2}}\right] = (2n+1)\frac{a}{\sqrt{a^2-1}} \left[\frac{I_n}{(a^2-1)^{n/2}}\right] - n\left[\frac{I_{n-1}}{(a^2-1)^{(n-1)/2}}\right],
$$
which means that $I_n = C(a^2-1)^{n/2}P_n(a/\sqrt{a^2-1})$ for some constant $C$. Since $I_0 = \pi$, we must have $C = \pi$, and
$$
\int_0^\pi(a+\cos\theta)^nd\theta = \pi(a^2-1)^{n/2}P_n\left(\frac{a}{\sqrt{a^2-1}}\right).
$$
A: $\int_0^{\pi} (a+\cos x)^n \ dx = \frac 12 \int_0^{2\pi} (a+\cos x)^n \ dx\\
\cos x = \frac 12 (e^{ix} + e^{-ix})\\
\frac 1{2^{n+1}} \int_0^{2\pi} (2a+e^{ix} + e^{-ix})^n \ dx
z = e^{ix}\\
dx = \frac {1}{iz}\ dz$
$\frac 1{2^{n+1}i} \oint_{|z| = 1} \frac {1}{z}(2a+z + z^{-1})^n \ dz$
Now the trick.  When we expand $(2a+z + z^{-1})^n$ we only care about the constant term.  The rest of the terms will evaluate to $0.$
$(2a+z + z^{-1})^n = \sum_\limits{k=0}^n {n\choose k} (z+z^{-1})^k(2a)^{n-k}$
There is only a constant term for $(z+z^{-1})^k$ if $k$ is even, and it will equal ${k\choose \frac{k}{2}}$
$\frac{\pi}{2^n}\sum_\limits{k=0}^{\lfloor \frac n2\rfloor} {n\choose 2k}{2k\choose k}(2a)^{n-2k}$
A: If your integral is $J_n$, the exponential generating function of the sequence $J_n$ is
$$ \eqalign{g(x) &= \sum_{n=0}^\infty \int_0^\pi \frac{(a+\cos(\theta))^n x^n}{n!}\; d\theta \cr
 &= \int_0^\pi \exp((a + \cos(\theta) x)\; d\theta\cr
&= \pi e^{ax} I_0(x)}$$
where $I_0$ is a modified Bessel function.  Since 
$$ e^{ax} = \sum_{j=0}^\infty \frac{a^j x^j}{j!}$$
and 
$$ I_0(x) = \sum_{k=0}^\infty \frac{x^{2k}}{4^k k!^2}$$
we get
$$ J_n = \pi n!\sum_{k=0}^{\lfloor n/2 \rfloor} \frac{a^{n-2k}}{4^k (n-2k)! k!^2}$$
