We have,
$
\begin{aligned}
y+x^2 & =\frac{d y}{d x} \\
\Rightarrow \quad \frac{d y}{d x}-y & =x^2
\end{aligned}
$
It is a linear differential equation. On comparing with $\frac{d y}{d x}+P y=Q$, we get
$
\begin{aligned}
& P=-1, Q=x^2 \\
& \mathrm{IF}=e^{\int P d x}=e^{\int-1 d x}=e^{-x}
\end{aligned}
$
Required solution is
$
\begin{aligned}
& & y \cdot e^{-x} & =\int x^2 e^{-x} d x+c \\
\Rightarrow & & y e^{-x} & =-x^2 e^{-x}+2 \int x e^{-x} d x \\
& \Rightarrow & y e^{-x} & =-x^2 e^{-x}-2 x e^{-x}+2 \int e^{-x} d x \\
& \Rightarrow & y e^{-x} & =-x^2 e^{-x}-2 x e^{-x}-2 e^{-x}+c \\
& \Rightarrow & y & =-\left(x^2+2 x+2\right)+c e^x \\
\Rightarrow & & y & +x^2+2 x+2=c e^x
\end{aligned}
$