Refer to Fig.
Mass per unit length of rod `= M//L`.
Consider a small element of the rod of mass `dm` and length `dr`.
Mass of the element, `dm = (M)/(l) dr`
Lat `r` be the distance of the particle `P` from the element of rod.
Gravitational force between the particle and the small element is
`dF = (Gm dm)/(r^(2)) = (G m)/(r^(2)) (M)/(L) dr = (GM m)/(L) (dr)/(r^(2))` ..(i)
Total gravitational force acting on the particle due to rod can be calculated by integrating equation (i) within the limits `r = d` to `r = (d + L)`, we have
`F = int dF = int_(r=d)^(r=d+L) (GM m)/(l) (dr)/(r^(2)) = (GM m)/(L) [-(1)/(r )]_(d)^(d + L) = - (GM m)/(L) [(1)/(d + L) - (1)/(d)] = (GM m)/(d(d + L))`