$\frac{d y}{d x}+2 y=\sin x$
The given differential equation is $\frac{d y}{d x}+2 y=\sin x$.
This is in the form of $\frac{d y}{d x}+p y=Q($ where $p=2$ and $Q=\sin x)$.
Now, I.F $=e^{\int p d x}=e^{\int 2 d x}=e^{2 x}$.
The solution of the given differential equation is given by the relation,
$y(\mathrm{IF} .)=\int(\mathrm{Q} \times \mathrm{I} . \mathrm{F} .) d x+\mathrm{C}$
$\Rightarrow y e^{2 x}=\int \sin x \cdot e^{2 x} d x+\mathrm{C}$ ...(1)
Let $I=\int \sin x \cdot e^{2 x} .$
$\Rightarrow I=\sin x \cdot \int e^{2 x} d x-\int\left(\frac{d}{d x}(\sin x) \cdot \int e^{2 x} d x\right) d x$
$\Rightarrow I=\sin x \cdot \frac{e^{2 x}}{2}-\int\left(\cos x \cdot \frac{e^{2 x}}{2}\right) d x$
$\Rightarrow I=\frac{e^{2 x} \sin x}{2}-\frac{1}{2}\left[\cos x \cdot \int e^{2 x}-\int\left(\frac{d}{d x}(\cos x) \cdot \int e^{2 x} d x\right) d x\right]$
$\Rightarrow I=\frac{e^{2 x} \sin x}{2}-\frac{1}{2}\left[\cos x \cdot \frac{e^{2 x}}{2}-\int\left[(-\sin x) \cdot \frac{e^{2 x}}{2}\right] d x\right]$
$\Rightarrow I=\frac{e^{2 x} \sin x}{2}-\frac{e^{2 x} \cos x}{4}-\frac{1}{4} \int\left(\sin x \cdot e^{2 x}\right) d x$
$\Rightarrow I=\frac{e^{2 x}}{4}(2 \sin x-\cos x)-\frac{1}{4} I$
$\Rightarrow \frac{5}{4} I=\frac{e^{2 x}}{4}(2 \sin x-\cos x)$
$\Rightarrow I=\frac{e^{2 x}}{5}(2 \sin x-\cos x)$
Therefore, equation (1) becomes:
$y e^{2 x}=\frac{e^{2 x}}{5}(2 \sin x-\cos x)+\mathrm{C}$
$\Rightarrow y=\frac{1}{5}(2 \sin x-\cos x)+\mathrm{C} e^{-2 x}$
This is the required general solution of the given differential equation.