According to the mathematical formula of work:
W=F.S=FSCosθ,
even if the displacement is not along the direction of force (except in the perpendicular direction), work will not be zero.
Derive the expression for work done when-
The displacement is in the direction of the force.