We claim that, for each \(k=0,1,\dots,n\text{,}\) the derivative \(g_n^{(k)}(x)\) for \(x \ne 0\) is a finite linear combination of terms of the form
\begin{equation*}
x^m \sin(1/x)
\qquad \text{and} \qquad
x^m \cos(1/x),
\end{equation*}
where \(m \ge 2n-2k\text{.}\) This is true for \(k=0\text{.}\) If it holds for some \(k\text{,}\) then differentiating one such term either lowers the power of \(x\) by \(1\) or by \(2\text{,}\) so after one more differentiation all exponents are still at least \(2n-2(k+1)\text{.}\) Thus the claim follows by induction.
In particular, if \(k \le n-1\text{,}\) then every exponent that occurs is at least \(2\text{.}\) Hence \(g_n^{(k)}(x) \to 0\) as \(x \to 0\text{.}\) Therefore \(g_n^{(k)}(0)=0\text{,}\) and
\begin{equation*}
\frac{g_n^{(k)}(h)-g_n^{(k)}(0)}{h}
=
\frac{g_n^{(k)}(h)}{h}
\to 0
\qquad \text{as } h \to 0,
\end{equation*}
because every term in \(g_n^{(k)}(h)/h\) still has a positive power of \(h\text{.}\) Thus \(g_n^{(k+1)}(0)\) exists and equals \(0\text{.}\) By induction, \(g_n \in D^n(\R)\text{.}\)
After differentiating exactly \(n\) times, there is a term with power \(x^0\text{:}\) it comes from differentiating the trigonometric factor in every step. So \(g_n^{(n)}(x)\) has the form
\begin{equation*}
g_n^{(n)}(x)=A(x)+B(x)\sin(1/x)+C(x)\cos(1/x)
\end{equation*}
for \(x \ne 0\text{,}\) where \(A,B,C\) are finite linear combinations of powers of \(x\) and at least one of \(B(0)\) or \(C(0)\) is nonzero. Consequently, \(g_n^{(n)}(x)\) oscillates as \(x \to 0\) and is not continuous at \(0\text{.}\) Hence \(g_n \notin C^n(\R)\text{.}\)