Figure 1

Let P be the point on the axis of a uniform disc of mass M and radius a, making an angle theta as shown in the figure above.
Let us consider an infinitesimal ring of width dr located at a distance r from the centre of disc and of mass
dm=(2πrdr)(M/(πa^2)) " "(Mass=areaxxdensity)
dm=(2M)/a^2rdr ......(1)
As shown in the figure below, we see that for an elemental part at A of the ring, Gravitational field at point P=dvecE_G.
All points on the ring are equidistant form point P. Hence, the magnitude of gravitational field due to any of the elemental mass of ring is same at P
If we resolve this gravitational field in directions along the axis and perpendicular to the plane OAP, we see that for each element on the ring there exists an element located diametrically opposite. Vertical component of gravitational field due to the pair is zero. Therefore, vertical components due to complete ring vanish due to symmetry.

Hence axial components for ring in figure 1 from Newton's law of Universal Gravitation are
dvecE_G=−(Gdmcosθ_e)/((r^2+x^2)), along the axis
where θ_e is angle subtended by the infinitesimal ring at P and is given as
cosθ_e=x/sqrt(r^2+x^2)
Inserting value from (1) and integrating over r=0 " to " r=a we get
|vecE_G|=∫_0^aGx((2M)/a^2rdr)/(r^2+x^2)^(3/2)
=>|vecE_G|=∫_0^a(2GMx)/a^2(r)/(r^2+x^2)^(3/2)dr
Using standard integral we get
=>|vecE_G|=(2GMx)/a^2[-1/(r^2+x^2)^(1/2)]_0^a
=>|vecE_G|=(2GMx)/a^2(-1/sqrt(a^2+x^2)+1/x)
=>|vecE_G|=(2GM)/a^2(1-x/sqrt(a^2+x^2))
=>|vecE_G|=(2GM)/a^2(1-costheta)