The heat gained or lost during heat exchange process can be calculated using:
q = m c ΔT
q is heat lost or gained (J), m is mass (g), c is specific heat capacity (J/g oC), and ΔT is change in temperature.
For your question:
q = -375 J (the sign indicates that heat is lost), m = 40 g, and ΔT = 21 - 45 = - 24 oC (the sign indicates decrease in temperature).
Now solve the above equation for specific heat capacity, c
c = q/mΔT
= -375 J/(40 g x (-24 oC))
= 0.39 J/g oC