A function differentiable on an open subset 
Let $f:\mathbb{R}\to \mathbb{R}$ be a function differentiable on an open subset $U$. Let $a\in U$. If $f$ attains a maximum or a minimum at $a$, prove that $\frac{\partial f}{\partial x_i}(a)=0$ for all $i$. 

I seen a proof by contradiction, but it wasn't very intuitive for me. Can someone help provide a more direct, clearer proof?

I will show you a proof if $f$ has a minimum in $a$. The proof for the maximum is similar. Since $f$ is differentiable $\lim_{t\to 0}\frac{f(a+te_i)-f(a)}{t}$ exists. Furthermore, $f(a+te_i)-f(a)\ge0$ for all $t$ in a small enough neighborhood of $0$. Now let $t\nearrow0$. Then $\frac{f(a+te_i)-f(a)}{t}\le0$, since $t<0$, so $\lim_{t\nearrow 0}\frac{f(a+te_i)-f(a)}{t}\le0$. You can use the same argument (letting $t\searrow 0$) to show $\lim_{t\searrow 0}\frac{f(a+te_i)-f(a)}{t}\ge0$. Then $\frac{\partial f}{\partial x_i}(a)=\lim_{t\to 0}\frac{f(a+te_i)-f(a)}{t}=0$.
