Definite integration when denominator consists of $x\sin x +1$ $$\int_0^\pi\frac{x^2\cos^2x-x\sin x-\cos x-1}{(1+x\sin x)^2}dx$$
The answer is $0$. I tried and made $(x\sin x +1)^2 $ in numerator and proceed, 
but not able to do any further.
 A: First, let us try and simplify the integrand a bit. As
\begin{align}
\frac{x^2 \cos^2 x - x \sin x - \cos x - 1}{(1 + x \sin x)^2} &= \frac{x^2 - x^2 \sin^2 x - x \sin x - \cos x - 1}{(1 + x \sin x)^2}\\
&= \frac{x^2 + x \sin x - \cos x - (1 + x \sin x)^2}{(1 + x \sin x)^2}\\
&= -1 + \frac{x^2 + x \sin x - \cos x}{(1 + x\sin x)^2},
\end{align}
we have for the integral
$$I = -\pi + \int_0^\pi \frac{x^2 + x \sin x - \cos x}{(1 + x \sin x)^2} = -\pi + J.$$
To find the integral $J$ one can make use of the so-called reverse quotient rule (For another example using this method see here). 
Recall that if $u$ and $v$ are differentiable functions, from the quotient rule
$$\left (\frac{u}{v} \right )' = \frac{u' v - v' u}{v^2},$$
and it is immediate that
$$\int \frac{u' v - v' u}{v^2} \, dx = \int \left (\frac{u}{v} \right )' \, dx = \frac{u}{v} + C. \tag1$$
For the integral $J$ we see that $v = 1 + x \sin x$. So $v' = \sin x + x \cos x$. Now for the hard bit. We need to find (conjure up?) a function $u(x)$ such that
$$u' v - v' u = u'(1 + x \sin x) - u (\sin x + x \cos x)  = x^2 + x \sin x - \cos x.$$
After a little trial and error we find that if
$$u = -x \cos x,$$
as
$$u' = -\cos x + x \sin x,$$
this gives
$$u' v - v' u = x^2 + x \sin x - \cos x,$$
as required.
Our integral can now be readily found as it can be rewritten in the form given by (1). The result is:
\begin{align}
I &= -\pi + \int_0^\pi \left (\frac{-x \cos x}{1 + x \sin x} \right )' \, dx\\
&= -\pi - \left [\frac{x \cos x}{1 + x \sin x} \right ]_0^\pi\\
&= -\pi + \pi\\
&= 0,
\end{align}
as announced. 
