Prove the following inequality for all $n \in \mathbb{N}$ Let $f(x)$ be a derivable function on the interval $(0,1)$ and continuous on $[0,1]$. 
Assume that $|f'(x)| \leq M$ for every $x \in (a,b)$. 
Prove the following inequality for all $n\in\mathbb{N}$,
$$
  \left| \int_0^1 f(x) dx - \frac{1}{n} \sum_{k=1}^n f(k/n) \right| \leq \frac{M}{n}.
$$
 A: If I'm not mistaken, we can get a slightly sharper bound.
Write
$$\int_0^1\,f(x)\,dx = \sum_{k=1}^n\int_{(k-1)/n}^{k/n}\,f(x)\,dx$$
so then we need to estimate
\begin{align}
&\left| \sum_{k=1}^n\left[\left(\int_{(k-1)/n}^{k/n}\,f(x)\,dx\right)-\frac1n f(k/n)\right]  \right|
\\=\,\,&
\left| \sum_{k=1}^n\left(\int_{(k-1)/n}^{k/n}\,f(x) - f(k/n)\,dx\right)  \right|.
\end{align}
Now, use the mean value theorem.
For each $x\in\Big((k-1)/n,\, k/n\Big)$, there is some $\eta_x \in (x,\,k/n)$ with
$$f(x) - f(k/n) = f'(\eta_x) \big(x-k/n\big).$$
Then our estimate becomes 
\begin{align}
&\left| \sum_{k=1}^n\left(\int_{(k-1)/n}^{k/n}\,f(x) - f(k/n)\,dx\right)  \right|
\\\leqslant \,\,&
\sum_{k=1}^n\int_{(k-1)/n}^{k/n}\,|f'(\eta_x)| \big(k/n - x\big)\,dx
\\\leqslant \,\,&
M\,\sum_{k=1}^n\int_{(k-1)/n}^{k/n}\,\big(k/n - x\big)\,dx
\\= \,\,&
M\,\sum_{k=1}^n\left[\frac{kx}n - \frac{x^2}2\right]_{(k-1)/n}^{k/n}
\\= \,\,&
M\,\sum_{k=1}^n\frac1{2n^2} = \frac M{2n}.
\end{align}

As a bonus, it's easy to verify that the bound is sharp when $f$ is affine (that is, when $f'$ is constant).
