We have two functions multiplied together: x and cos(x).
Therefore we have to use the product rule.
First differentiate x and leave cos(x) untouched, so we get 1(cos(x))=cos(x). Then differentiate cos(x) and leave x untouched giving us x(-sin(x))=-xsin(x).
Finally add the two parts together which gives us cos(x) + -xsin(x)=cos(x)-xsin(x).