$$a_n = \frac 1 \pi \int_{-\pi}^{\pi} f(x) cos(nx) dx \quad\quad n\ge1 $$
Now I am wondering why there is a separate formula for $a_0$:
$$a_0 = \frac 1 \pi \int_{-\pi}^{\pi} f(x) dx$$
It looks equivalent to the formula for $a_n$, just with $n=0$:
$$\frac 1 \pi \int_{-\pi}^{\pi} f(x) cos(0\cdot x) dx = \frac 1 \pi \int_{-\pi}^{\pi} f(x) \cdot 1 dx = \frac 1 \pi \int_{-\pi}^{\pi} f(x) dx$$
So for a recent exercise I wanted to be clever and skipped the separate integral for $a_0$ and just calculated $a_n$, and then substituted $n=0$ to get the value for $a_0$.
But it turned out to give the wrong answer. Why is that?
P.S. the exercise was ("falls" = "if/when"):

Edit: I calculated $a_0$ like this:
$$a_0 = \frac 1 \pi \int_{-\pi}^{\pi} f(x) \, dx = \frac 1 \pi \int_{-\pi}^0 0 \, dx + \frac 1 \pi \int_0^\pi (e^x-1) \, dx = \frac 1 \pi [e^x - x]_0^\pi = \frac 1 \pi [e^\pi - \pi - 1] $$
For $a_n$ I just used Wolfram Alpha:

I evaluated the above result with $n=0$, multiplied by $\frac 1 \pi$ and got:
$$ \frac 1 \pi [e^\pi - 1] $$
Edit 2: Looks like I should have treated that last Wolfram Alpha term as a limit, to get that missing $-\pi$:
$$ \lim_{n \to 0} \left[-\frac{sin(\pi n)}{n}\right] = \lim_{n \to 0} \left[-\frac{\pi cos(\pi n)}{1}\right] = - \frac{\pi}{1} = - \pi $$