When we use integration by parts, we have a choice for \(u\) and \(dv\text{.}\) In this problem, we can either let \(u = x\) and \(dv = \cos(x) \, dx\text{,}\) or let \(u
= \cos(x)\) and \(dv = x \, dx\text{.}\) While there is not a universal rule for how to choose \(u\) and \(dv\text{,}\) a good guideline is this: do so in a way that \(\int v \,
du\) is at least as simple as the original problem \(\int u \, dv\text{.}\)
This leads us to choose\(u = x\) and \(dv = \cos(x) \, dx\text{,}\) from which it follows that \(du = 1 \, dx\) and \(v = \sin(x)\text{.}\) With this substitution, the rule for integration by parts tells us that
\begin{equation*}
\int x \cos(x) \, dx = x \sin(x) - \int \sin(x) \cdot 1 \, dx
\end{equation*}
.
All that remains to do is evaluate the (simpler) integral \(\int \sin(x)
\cdot 1 \, dx\text{.}\) Doing so, we find
\begin{equation*}
\int x \cos(x) \, dx = x \sin(x) - (-\cos(x)) + C = x\sin(x) + \cos(x) + C\text{.}
\end{equation*}
Observe that when we get to the final stage of evaluating the last remaining antiderivative, it is at this step that we include the integration constant, \(+C\text{.}\)