Let, $C(\Bbb R):=\\ \{f:\Bbb R \to \Bbb R| \text{ $f$ is continuous and $\exists$ a compact set $K$ such that $f(x)=0$, $\forall x\in K^c$}\}.$ Let, $\displaystyle g(x)=e^{-x^2}$ for all $x\in \Bbb R$. Then prove that there exists a sequence $\{f_n\}$ in $C(\Bbb R)$ such that $f_n \to g$ uniformly.
Here $g$ is continuous, so by Weierstress approximation theorem we can say that there always exists a sequence of polynomials $\{p_n(x)\}$ in $K$ which converges uniformly to $g$ in $K$. But in that case how can I define $f_n(x)$ in such a way that $f_n \in C(\Bbb R)$ ?
Since $g$ tends to $0$ as $x\rightarrow\infty$ you can just take $f_n = g\phi_n$ where $\phi_n$ is a smooth (for your questions continuous is sufficient) cutoff function such
$\phi_n(x)=1$ on $[-n,n]$, $\phi_n(x)=0$ on $(-\infty,-n-1]\cup[n+1,\infty)$, and $0\le \phi_n(x) \le 1$ elsewhere.