12.12 If $i^{2}=-1$, then the sum $S=\cos 45^{\circ}+i \cos 135^{\circ}+\cdots+i^{n} \cos (45+90 n)^{\circ}+\cdots+i^{40} \cos 3645^{\circ}$ equals
(A) $\frac{\sqrt{2}}{2}$.
(B) $-10 \sqrt{2} i$.
(C) $\frac{21 \sqrt{2}}{2}$.
(D) $\frac{\sqrt{2}}{2}(21-20 i)$.
(E) $\frac{\sqrt{2}}{2}(21+20 i)$.
(28th American High School Mathematics Examination, 1977)
[Solution] Since $i^{n} \cos (45+90 n)^{\circ}=\left\{\begin{array}{ll}\frac{\sqrt{2}}{2}, & n \text { is even. } \\ \frac{-i \sqrt{2}}{2}, & n \text { is odd. }\end{array}\right.$
$$
\begin{aligned}
\therefore \quad S & =\frac{\sqrt{2}}{2}(\underbrace{1-i+1-i+\cdots+1-i+1}_{41 \text { terms }}) \\
& =\frac{\sqrt{2}}{2}(21-20 i) .
\end{aligned}
$$

Therefore, the answer is $(D)$.