(N/A) Imagine the Earth to be a sphere made of a large number of concentric spherical shells with the smallest one at the centre and the largest one at its surface.
$A$ point outside the Earth is outside all the shells. Thus,all the shells exert a gravitational force at the point outside just as if their masses were concentrated at their common centre.
For a point inside the Earth,the situation is different. Consider the Earth to be made up of concentric shells. $A$ point mass $m$ is situated at a distance $r$ $(r < R_E)$ from the centre. The point $P$ lies outside the sphere of radius $r$. For the shells of radius greater than $r$,the point $P$ lies inside. Hence,no net gravitational force is exerted by these outer shells on mass $m$ kept at $P$.
If the mass of the particle is $m$ at $P$,and the mass of the inner sphere of radius $r$ is $M_r$,then the force on the mass $m$ at $P$ has a magnitude:
$F = \frac{G m M_r}{r^2}$
Assuming the entire Earth has a uniform density $\rho$,its total mass is $M_E = (\frac{4}{3} \pi R_E^3) \rho$.
Therefore,$\rho = \frac{M_E}{\frac{4}{3} \pi R_E^3}$.
The mass of the inner sphere is $M_r = (\frac{4}{3} \pi r^3) \rho = (\frac{4}{3} \pi r^3) \frac{M_E}{\frac{4}{3} \pi R_E^3} = M_E \frac{r^3}{R_E^3}$.
Substituting $M_r$ into the force equation:
$F = \frac{G m}{r^2} (M_E \frac{r^3}{R_E^3}) = \frac{G M_E m r}{R_E^3}$.
Since $F = mg_r$,the acceleration due to gravity at distance $r$ is $g_r = \frac{G M_E r}{R_E^3}$.
On the surface of the Earth,$r = R_E$. Substituting this into the equation:
$g = \frac{G M_E R_E}{R_E^3} = \frac{G M_E}{R_E^2}$.