Above we see the four steps which make up an ideal gas Carnot cycle, two isothermal, (i) and (iii), and two adiabatic, (ii) and (iv). Below the cycle is sketched on a plot.
We have already analyzed this particular cycle (see here.) We worked out the work for the four steps. We note further that the heat exchanged during the isothermal steps is just minus the work done, since the internal energy is unchanged.
Thus we have
and (from stage iii)
Note this cycle wasn't general, because we chose to make both the isothermal and adiabatic stages volume-halving. But form of the answer is general.