Example 7. Calculate $\int_{0}^{\pi} x \sin x d x$.
Solution. Integrating by parts, we get

$$
\begin{aligned}
& \int_{0}^{\pi} x \sin x d x=\int_{0}^{\pi} x d(-\cos x)=\left.x(-\cos x)\right|_{0} ^{\pi}-\int_{0}^{\pi}(-\cos x) d x= \\
= & -\left.x \cos x\right|_{0} ^{\pi}+\left.\sin x\right|_{0} ^{\pi}=-(\pi \cos \pi-0 \cdot \cos 0)+(\sin \pi-\sin 0)=\pi
\end{aligned}
$$