Proving the $(n+1)$th moment of a continuous random variable Let $X$ be a continuous random variable with the probability density function
$$
f(x)=\left\{\begin{array}{cc}
\frac{x \sin x}{\pi}, & 0<x<\pi \\
0, & \text { otherwise. }
\end{array}\right.
$$
Prove that $\mathbb{E}\left(X^{n+1}\right)+(n+1)(n+2) \mathbb{E}\left(X^{n-1}\right)=\pi^{n+1}$.

I've tried computing the first part $E(X^{n+1})$ and here's what I get:
Proof
Let $k = n+1$. Notice that
$$F_X(x) = \frac{1}{\pi}\int_0^{x} y \sin (y) \,dy = \frac{1}{\pi}(\sin(x) - x \cos(x)) $$
Then, using the identity $E(X^n) = n \int_0^{\infty}x^{n-1}(1-F_X(x)) \,dx$,
$$E(X^k) = k \int_0^{\pi} x^{k-1} (1-Fx(x)) \,dx$$
$$= k \int_0^{\pi} x^{k-1} (1-\frac{1}{\pi}(\sin(x) - x \cos(x)) \,dx $$
$$= k \int_0^{\pi} x^{k-1} - \frac{x^{k-1}}{\pi} \sin(x) - \frac{x^k}{\pi} \cos(x) \,dx $$
But I can't compute the definite integral of $x^k \cos(x) \,dx$. Well, at least not in the course I'm doing, we are not learning gamma functions. The solutions say to "use integration by parts twice" and that's it.
Is the way I'm going about this just completely wrong? How else could I prove this?
 A: 
The solutions say to "use integration by parts twice"

Let's do that!
$$\mathbb{E}[X^{n+1}]=\frac{1}{\pi}\int_0^{\pi}x^{n+2}\sin x dx=\left[-x^{n+2}\frac{\cos x}{\pi}\right]_0^{\pi}+\frac{1}{\pi}\int_0^{\pi}(n+2)x^{n+1}\cos xdx=$$
$$=\pi^{n+1}+(n+2)\int_0^{\pi}  x^{n+1}\frac{\cos x}{\pi}dx=$$
$$=\pi^{n+1}+\underbrace{(n+2)\left[\frac{x^{n+1}}{\pi}\sin x   \right]_0^{\pi}}_{=0}-(n+2)(n+1)\underbrace{\int_0^{\pi}x^{n-1}\frac{x\sin x}{\pi}dx}_{\mathbb{E}[X^{n-1}]}$$
thus
$$\mathbb{E}[X^{n+1}]+(n+2)(n+1)\mathbb{E}[X^{n-1}]=\pi^{n+1}$$
A: You can just use the most simple formula $E(X^n) = \int x^n f(x) dx$. I help you do the first integration by parts, you can do the second one.
\begin{align*} 
E(X^{n+1}) &=  \int^\pi_0 \frac{x^{n+2}\sin(x)}{\pi} dx \\ 
 &= \left[-\frac{x^{n+2}\cos(x)}{\pi}\right]^\pi_0 + (n+2)\int^\pi_0 \frac{x^{n+1}\cos(x)}{\pi} dx \\
  &= \pi^{n+1} + (n+2)\int^\pi_0 \frac{x^{n+1}\cos(x)}{\pi} dx \\
  &= \cdots \text{ (second integration by parts)} \\
  &= \pi^{n+1} - (n+1)(n+2)E(X^{n-1})
\end{align*}
Then, rearrange the terms can you can get the final result.
