detail in proof of the mean value theorem for integrals I am trying to prove the following result

If $f$ is a continuous function on a closed interval $[a,b]$, then
there exists a $c \in (a,b)$ such that,
$$f(c)=\frac{1}{b-a}\int_a^bf(x)\;\mathrm{d}x$$

I have worked out the following proof
Because $f$ is continuous on the interval, it reaches a minimum $m$, and a maximum $M$ so that we have
$$\begin{aligned} m&\leq f(x)\leq M \\ m(b-a)\leq  & \int_a^bf(x)\;\mathrm{d}x\leq M(b-a) \\  m\leq &\frac{1}{b-a}\int_a^bf(x)\;\mathrm{d}x\leq M\end{aligned}$$
and the IVT guarantees the exxistence of $c$ as above.
How do I prove that $c \neq a\ \& \ c\neq b$?
Thanks for the help !
 A: If $f$ is constant, there is nothing to do.
Otherwise, let $M=\max f$ and $m=\min f$ on $[a,b]$ with $m\neq M.$ Then, $m\le \frac{\int_a^bf(t)dt}{b-a}\le M$ so the Intermediate Value Theorem gives us a $c\in [a,b]$ such that $f(c)=\frac{\int_a^bf(t)dt}{b-a}.$
If $c\in (a,b),$ we are done.
If $c=a$ then $f(a)=\frac{\int_a^bf(t)dt}{b-a}.$ If $f(a)=m,$ then $\int_a^b(f(t)-m)dt=0$ and since $f-m\ge 0$ on $[a,b]$ and continuous there, $f-m=0$ and $f$ is constant. Similarly, if $f(a)=M$ we get $f=M$.
So there are $a<x_0\neq x_1<b$ such that $f(x_0)=m$ and $f(x_1)=M.$ Without loss of generality, $x_0<x_1.$
Then, $m<f(a)<M$ so appying the IVT again, we get a $x_0\le d\le x_1$ such that $f(d)=f(a)$ and the result follows.
An almost identical argument shows that the result also holds if $c=b.$
A: Assume $w<z, w,z\in [a,b]$ with $f(w) = m, f(z) = M$
If $m=M \implies f$ is a constant function then all $c\in(a,b)$ works.
Suppose $m<M$
We have that for $c\in [w,z]$, $f(c) = \frac{1}{b-a}\int_{a}^{b}f(x)dx$
Suppose $c = a$, then $a = w$, because $a\leq w \leq c \leq  z \leq b$
Then $f(a) = m$ is the  minimum of the function
$f(z) =M>m \implies$ there exist some $\delta >0$ such that $f(x)>m+\epsilon$ for some $\epsilon>0$ for all $x\in (z-\delta,z]$
Thus we have that $\begin{aligned}\int_{a}^{b}f(x)dx & = \underbrace{\int_{a}^{z-\delta}f(x)dx}_{\geq f(a)\cdot(z-\delta -a)} +\underbrace{\int_{z-\delta}^{z}f(x)dx}_{\geq (f(a) + \epsilon)\cdot\delta>f(a)\cdot \delta}+\underbrace{\int_{z}^{b}f(x)dx}_{\geq f(a)\cdot(b-z)}>f(a)\cdot(b-a)\\  &\underbrace{\frac{1}{b-a}\int_{a}^{b}f(x)dx}_{f(c)} > f(a)\end{aligned}$
that is a contradiction. Then $c \neq a$
I hope it help you,
I think the other cases will be analogous
(for example, apply this reasoning to $-f$)
A: Here is another approach. Assume that $$f(x) > K=\frac{1}{b-a}\int_a^b f(x) \, dx$$ for all $x\in(a, b) $. This means that $g(x) =f(x) - K>0$ for all $x\in(a, b) $. Hence $$\int_{a} ^{b} g(x) \, dx>0$$ ie $$\int_{a} ^ {b} f(x) \, dx>K(b-a) $$ which is absurd.
Similarly one can show that $f(x) <K$ for all $x\in(a, b) $ can't hold. Thus by intermediate value theorem we must have $f(c) =K$ for some $c\in(a, b) $.
A: Sometimes a figure is worth 1000 words:

What is the area in blue?
$$\int\limits_a^b f(x)\ dx$$
What is the area in orange?
$$f(c) \cdot (b-a)$$
QED.
