A spring is streched 40mm by a force of 15n .what is the workdone

average F = 7.5 Newtons (use av because F = k x is linear)

work = force times distance in direction of force
= 7.5 Newtons * 40*10^-3 meters = 0.300 Joules

If you do calculus by the way

if F = k x
then
W = integral F dx = integral k x dx = (1/2)k x^2 = (1/2) * Fmax * x max