Center of the dihedral group with odd and even number of vertices
Solution 1:
$D_{2n}$ has presentation $\langle r,f\mid r^n,f^2,(rf)^2\rangle $.
If $n$ is odd, $f,r,r^2,\dots, r^{n-1}$ are not in the center, since $rf=fr^{-1}$.
Similarly, $r^af,1\le a\le n-1$ is not, because $(r^af)f=r^a$ but $f(r^af)=ffr^{-a}=r^{-a}$.
That leaves just $\{e\}$ for $n$ odd.
We get $\{e,r^{\frac n2}\}$, for $n$ even, since $r^{\frac n2}f=fr^{\frac n2}$.