Question: How can I solve this indefinite integral for an arbitrary integer $n>0$?

$$ \int{x^n e^x dx}$$

I could partially integrate it for small $n$, but that's not really a solution.

---

**Edit:** (TB) This question is closely related to: [Is there a closed form solution for $\int x^n e^{cx}$?](https://math.stackexchange.com/questions/21516/is-there-a-closed-form-solution-for-int-xn-ecx), but it is more elementary, because $n$ is an integer here.

Answer: 
You could use the generating function approach.  

$$ \eqalign{\int\_0^X e^{tx} e^x \ dx &= \frac{e^{(1+t)X} - 1}{1+t}\cr 
&= \sum\_{k=0}^\infty (-1)^k t^k \left(e^X -1 + \sum\_{j=1}^\infty e^X \,\frac{X^j}{j!} t^j\right)\cr
 &= \sum\_{n=1}^\infty \left((-1)^n (e^X - 1) + \sum\_{j=1}^n (-1)^{n-j} \frac{X^j}{j!} e^X \right) t^n\cr}$$
But also 
$$ \int\_0^X e^{tx} e^x \, dx = \sum\_{n=0}^\infty \frac{t^n}{n!} \int\_0^X x^n e^x \, dx$$
Equating coefficients of $t^n$ from both sides,
$$ \int\_0^X x^n e^x\, dx = (-1)^n n! (e^X - 1) +
\sum\_{j=1}^n (-1)^{n-j} \frac{n!}{j!} X^j e^X $$
I find it a little difficult for me to guess the solution by trying several $n$. I would like to do it as following:

$$\begin{align}\int x^ne^xdx&=x^ne^x+(-1)n\int x^{n-1}e^xdx,\qquad n\geq 1\\
\int x^0e^xdx&=e^x\end{align}$$

Then you get the recurrence relation:

$$\begin{align}a\_n(x)&=x^ne^x+(-1)na\_{n-1}(x),\qquad n\geq 1\\
a\_0(x)&=e^x\end{align}$$

With the recursive formula, it may be easier to find the *pattern* of the result.