We are given the differential equation:
\[
\frac{dy}{dx} + y \cos x = \frac{1}{2} \sin 2x
\]
This is a first-order linear differential equation. To solve this equation, we use the method of integrating factors. The standard form of a linear first-order differential equation is:
\[
\frac{dy}{dx} + P(x)y = Q(x)
\]
Here, \( P(x) = \cos x \) and \( Q(x) = \frac{1}{2} \sin 2x \).
Step 1: Find the integrating factor
The integrating factor is given by:
\[
\mu(x) = e^{\int P(x) \, dx} = e^{\int \cos x \, dx} = e^{\sin x}
\]
Step 2: Multiply through by the integrating factor
Multiplying the entire differential equation by \( e^{\sin x} \), we get:
\[
e^{\sin x} \frac{dy}{dx} + y e^{\sin x} \cos x = \frac{1}{2} e^{\sin x} \sin 2x
\]
Now, the left side is the derivative of \( y e^{\sin x} \), so the equation becomes:
\[
\frac{d}{dx} \left( y e^{\sin x} \right) = \frac{1}{2} e^{\sin x} \sin 2x
\]
Step 3: Integrate both sides
Now, we integrate both sides:
\[
y e^{\sin x} = \int \frac{1}{2} e^{\sin x} \sin 2x \, dx + c
\]
After performing the integration, the solution is:
\[
y e^{\sin x} = e^{\sin x (sin x - 1)} + c
\]
Thus, the correct answer is option (B).