Suppose \(f\) has a local maximum at \(c\text{.}\) Then for all \(x\) sufficiently close to \(c\text{,}\) we have \(f(x)-f(c) \le 0\text{.}\) If \(x \lt c\text{,}\) then \(x-c \lt 0\text{,}\) so
\begin{equation*}
\frac{f(x)-f(c)}{x-c} \ge 0.
\end{equation*}
If \(x \gt c\text{,}\) then \(x-c \gt 0\text{,}\) so
\begin{equation*}
\frac{f(x)-f(c)}{x-c} \le 0.
\end{equation*}
Since the derivative exists, both one-sided limits of the difference quotient equal \(f'(c)\text{.}\) Hence \(f'(c) \ge 0\) and \(f'(c) \le 0\text{,}\) so \(f'(c)=0\text{.}\) The proof for a local minimum is analogous.