$\cos ^{2} x \frac{d y}{d x}+y=\tan x\left(0 \leq x<\frac{\pi}{2}\right)$
The given differential equation is:
$\cos ^{2} x \frac{d y}{d x}+y=\tan x$
$\Rightarrow \frac{d y}{d x}+\sec ^{2} x \cdot y=\sec ^{2} x \tan x$
This equation is in the form of:
$\frac{d y}{d x}+p y=Q$ (where $p=\sec ^{2} x$ and $Q=\sec ^{2} x \tan x$ )
Now, I.F $=e^{\int p d x}=e^{\int \sec ^{2} x d x}=e^{\tan x}$.
The general solution of the given differential equation is given by the relation,
$y(\mathrm{I.F} .)=\int(\mathrm{Q} \times \mathrm{I.F} .) d x+\mathrm{C}$
$\Rightarrow y \cdot e^{\tan x}=\int e^{\tan x} \cdot \sec ^{2} x \tan x d x+\mathrm{C}$ ...(1)
Let $\tan x=t .$
$\Rightarrow \frac{d}{d x}(\tan x)=\frac{d t}{d x}$
$\Rightarrow \sec ^{2} x=\frac{d t}{d x}$
$\Rightarrow \sec ^{2} x d x=d t$
Therefore, equation (1) becomes:
$y \cdot e^{\tan x}=\int\left(e^{t} \cdot t\right) d t+\mathrm{C}$
$\Rightarrow y \cdot e^{\tan x}=\int\left(t \cdot e^{t}\right) d t+\mathrm{C}$
$\Rightarrow y \cdot e^{\tan x}=t \cdot \int e^{t} d t-\int\left(\frac{d}{d t}(t) \cdot \int e^{t} d t\right) d t+\mathrm{C}$
$\Rightarrow y \cdot e^{\tan x}=t \cdot e^{t}-\int e^{\prime} d t+\mathrm{C}$
$\Rightarrow y e^{\tan x}=(t-1) e^{t}+\mathrm{C}$
$\Rightarrow y e^{\tan x}=(\tan x-1) e^{\tan x}+\mathrm{C}$
$\Rightarrow y=(\tan x-1)+\mathrm{C} e^{-\tan x}$