A spring is compressed by 0.03 calculate the energy stored in the spring.if the force constant is 400N/M

Potential energy stored in spring = (1/2) k x^2

assuming you mean 0.03 meters:
U = (1/2)(400) N/m * (0.03)^2 m^2 = 0.18 Joules

You get that from

F = k x
work in = energy gained = integral F dx from 0 to x
= (1/2) k x^2