Assume the cost price of toy be Rs x.
Selling price = Rs.24
Given: Gain % = x %
(24 - x)/x = x/100
2400-100x = x2
x2+ 100 x - 2400 =0
x2+ 120 x - 20 x- 2400 =0
x(x+120) -20(x+120)=0
(x+120)(x-20)=0
x = -120 (not possible) so x =Rs 20 is the cost price of the toy.