Let the final temperature of mixture be ToC, then Heat given by steam = Heat taken by ice
m1L1+mS1t1=m2L2+m2S2t2, where t1 and t2 indicate change in temperatures.
⇒8×2268+8×4.2×(100−T)=40×336+40×4.2×(T−0)
⇒18144+3360−33.6T=13440+168T
⇒201.6T=8064⇒T=8064201.6=806402016=40oC