$x \frac{d y}{d x}+y-x+x y \cot x=0(x \neq 0)$
$x \frac{d y}{d x}+y-x+x y \cot x=0$
$\Rightarrow x \frac{d y}{d x}+y(1+x \cot x)=x$
$\Rightarrow \frac{d y}{d x}+\left(\frac{1}{x}+\cot x\right) y=1$
This equation is a linear differential equation of the form:
$\frac{d y}{d x}+p y=Q\left(\right.$ where $p=\frac{1}{x}+\cot x$ and $\left.Q=1\right)$
Now, I.F $=e^{\int p d x}=e^{\int\left(\frac{1}{x}+\cot x\right) d x}=e^{\log x+\log (\sin x)}=e^{\log (x \sin x)}=x \sin x$
The general solution of the given differential equation is given by the relation,
$y(\mathrm{I} . \mathrm{F} .)=\int(\mathrm{Q} \times \mathrm{I} . \mathrm{F} .) d x+\mathrm{C}$
$\Rightarrow y(x \sin x)=\int(1 \times x \sin x) d x+\mathrm{C}$
$\Rightarrow y(x \sin x)=\int(x \sin x) d x+\mathrm{C}$
$\Rightarrow y(x \sin x)=x \int \sin x d x-\int\left[\frac{d}{d x}(x) \cdot \int \sin x d x\right]+\mathrm{C}$
$\Rightarrow y(x \sin x)=x(-\cos x)-\int 1 \cdot(-\cos x) d x+\mathrm{C}$
$\Rightarrow y(x \sin x)=-x \cos x+\sin x+\mathrm{C}$
$\Rightarrow y=\frac{-x \cos x}{x \sin x}+\frac{\sin x}{x \sin x}+\frac{\mathrm{C}}{x \sin x}$
$\Rightarrow y=-\cot \cdot x+\frac{1}{x}+\frac{\mathrm{C}}{x \sin x}$