I shall prove the generalization of $$\cos x+\cos(x+120^\circ)+\cos(x+240^\circ)=0$$ (here $x=40^\circ$)
$$S=\sum_{r=0}^{n-1}\cos\left(x+\dfrac{360^\circ r}n\right)=0$$
Method $\#1:$
$S=$ real part of $\sum_{r=0}^{n-1} \exp i\left(x+\dfrac{360^\circ r}n\right)$
Now $\displaystyle \sum_{r=0}^{n-1} \exp i\left(x+\dfrac{360^\circ r} n \right) = \frac{e^{i360^\circ}-1}{\exp i\left(x+\dfrac{360^\circ(-n)}n\right)-1}=0$
Now equate the real & the imaginary parts.
Method $\#2:$
Using multiple angle formula cosine:
$$\cos(nx)=2^{n-1}\cos^nx-n2^{n-3}\cos^{n-2}x+\cdots$$
Now if $\cos nx=\cos ny, nx=360^\circ m\pm ny$ where $m$ is any integer
$x= y+\dfrac{360^\circ m}n$ where $m\equiv0,1,2,\ldots, n-1\pmod n$
So, the roots of $$2^{n-1}\cos^nx-n2^{n-3}\cos^{n-2}x+\cdots-\cos ny=0$$ are
$\cos\left(y+\dfrac{360^\circ m}n\right)$ where $m\equiv0,1,2,\ldots n-1\pmod n$
Using Vieta's formula,
$$\sum_{r=0}^{n-1}\cos\left(y+\dfrac{360^\circ m}n\right)=\dfrac0{2^{n-1}}$$