Given a spherically symmetric charge density $\rho(r)=\begin{cases}kr^2, & r<R \\ 0, & r>R\end{cases}$ (k being a constant), the electric field for $r<R$ is (take the total charge as $Q$)
Step 1: Compute enclosed charge for $r<R$.
$\rho(r)=kr^2$. Total charge inside radius $r$ is
$\displaystyle Q_{\text{enc}}=\int_0^r \rho(r')\,4\pi r'^2\,dr'
=4\pi k\int_0^r r'^4\,dr'
= \dfrac{4\pi k r^5}{5}.$
Step 2: Compute total charge $Q$ of the sphere.
$Q = \dfrac{4\pi k R^5}{5}.$
Thus
$k = \dfrac{5Q}{4\pi R^5}.$
Step 3: Substitute $k$ into $Q_{\text{enc}}$.
$Q_{\text{enc}} = \dfrac{5Q}{4\pi R^5}\cdot \dfrac{4\pi r^5}{5} = Q\left(\dfrac{r}{R}\right)^5.$
Step 4: Apply Gauss's law.
$E(4\pi r^2)=\dfrac{Q_{\text{enc}}}{\epsilon_0}$.
Thus
$\displaystyle E = \dfrac{Q}{4\pi\epsilon_0 R^5}\,r^3.$
Step 5: Conclusion.
Electric field for $r<R$ is $\dfrac{Qr^3}{4\pi\epsilon_0 R^5}\hat{r}.$
