Solution (source code)

= Solution

Set $h=(b-a)/n$ and $x_i=a+ih$. Summing the areas of the $n$ endpoint trapezia gives the <composite trapezoidal rule>
$$
\boxed{T_n=h\left[\frac{f(x_0)+f(x_n)}2+\sum_{i=1}^{n-1}f(x_i)\right].}
$$
Every interior value is shared by two adjacent strips; the two endpoint values occur only once with half weight. Evenness of $n$ is not needed for this rule.