Let the two buildings be AB and CD
height of the first building AB =40 cm
Height of the second building CD =50 cm
Distance between their foot = BD =24 cm
Draw AE || BD touching CD at E
Now CE = CD - DE
CE =50 - 40 =10 (DE = AB)
In Δ ACE, applying pythagoras theorem we get.
AC2=AE2+CE2
AC2=(24)2+(10)2
AC2=576+100=676
AC =26 cm
Hence, the distance between the tops of the buildings i.e AC =26 cm