Solution (source code)

= Solution

Take a fixed amount of dry air, with no phase change, moving quasistatically so that its <pressure> matches the surrounding atmosphere. From the <first law of thermodynamics> and $H=U+pV$,
$$
dH=dU+p\,dV+V\,dp=dq+V\,dp.
$$
For adiabatic motion $dq=0$. Treating the parcel as an <ideal gas> of fixed composition makes its <enthalpy> depend only on <temperature>, so for $n$ moles $dH=nC_p\,dT$ even though the <pressure> changes. Hence $nC_p\,dT=V\,dp$. The environment is in <hydrostatic equilibrium>, $dp/dz=-\rho g$, and the parcel is taken to have the ambient density at the displacement point. Using $\rho=nM/V$ gives
$$
nC_p\frac{dT}{dz}=V\frac{dp}{dz}=-nMg,
\qquad\boxed{\frac{dT}{dz}=-\frac{Mg}{C_p}=-\frac{g}{c_p}.}
$$
Here $C_p$ is molar and $c_p=C_p/M$ is mass-specific <heat capacity>. Positive $z$ points upward; the commonly quoted positive <dry adiabatic lapse rate> is $\Gamma_d=-dT/dz$. Approximate constancy of $g$ and <heat capacity> gives a constant gradient. Condensation, external heating, <entrainment> or composition changes invalidate this dry-parcel relation.