M → HiHo\frac{Hi}{Ho}HoHi = DiDo\frac{Di}{Do}DoDi
where M is the magnification, Hi is the height of the image, Ho is the height of the object, Di is the distance from the lens to the in-focus projected image, and Do is the distance from the object to the lens.
But Di = Hi⋅DoHo\frac{Hi \cdot Do}{Ho}HoHi⋅Do → 20⋅3040\frac{20 \cdot 30}{40}4020⋅30
Image distance(Di) = 15cm