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: 
Hint: Use integration by parts.

EDIT: Try several values of $n$.
$$
\int {x e^x dx} = (x - 1)e^x + C
$$
$$
\int {x^2 e^x dx} = (x^2 - 2x + 2)e^x + C.
$$
$$
\int {x^3 e^x dx} = (x^3 - 3x^2 + 6x - 6)e^x + C.
$$
$$
\int {x^4 e^x dx} = (x^4 - 4x^3 + 12x^2 - 24x + 24)e^x + C.
$$
$$
\int {x^5 e^x dx} = (x^5 - 5x^4 + 20x^3 - 60x^2 + 120x - 120)e^x + C.
$$
Conclude that
$$
\int {x^n e^x dx} = \bigg[\sum\limits\_{k = 0}^n {( - 1)^{n - k} \frac{{n!}}{{k!}}x^k } \bigg]e^x + C.
$$
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.