D- this means that the person went outside in order to smoke.
C- this means that the person was smoking while leaving- they had started smoking before they left. It's a possible sentence, but not natural.
I imagine the answer the test is looking for is D.
Student or Learner