Why $Z_p$ is closed. Let $A_n=\mathbb{Z}/p^n\mathbb{Z}$ be a ring and $p$ is prime, $\phi_n: A_n\rightarrow A_{n-1}$ be a natural homomorphism (Elements of $A_{n}$ define in an obvious way elements of $A_{n-1}$).
Define $p-adic$ integers $Z_p = \varprojlim (A_n,\phi_n)$, whose elements are $(...,x_n...,x_1)$ with $x_n \in A_n$ and $\phi_n(x_n)=x_{n-1}$ if $n \geq 2.$ So $Z_p$ is a subring of $\prod A_n$.

Give $A_n$ the discrete topology, $\prod A_n$ product topology, then $Z_p$ is closed in $\prod A_n$.

How to prove the above argument? Is any single element in $Z_p$ closed? 
 A: Let $A$ be the product, endowed with the product topology, and note $\pi_n : A \to \mathbf{Z}/p^n \mathbf{Z}$ for $n\geq 1$ the projection. It is continuous by definition of the product topology. Then $\mathbf{Z}_p = \cap_{n\in\mathbf{N}^{*}} \{x=(x_n)_{n\geq 1}\in A\;|\;\varphi_{n}(x_n) = x_{n-1}\} =$ $ \cap_{n\in\mathbf{N}^{*}} \{x=(x_n)_{n\geq 1}\in A\;|\;\varphi_{n}(\pi_n(x)) = \pi_{n-1}(x)\}$ and each $\{x=(x_n)_{n\geq 1}\in A\;|\;\varphi_{n}(\pi_n(x)) = \pi_{n-1}(x)\}$ is closed by continuity of the projection, and by continuity of the $\varphi_n$ (the latter are continuous, as the $\mathbf{Z}/p^n \mathbf{Z}$ have the discrete topology !). So $\mathbf{Z}_p$ is an intersection of closed subset of the product, and is therefore closed.
Remark : $\mathbf{Z}_p$ is compact : indeed, it is closed in $A$ which is product of compact sets (indeed, if finite set with the discrete topology is compact, and the $\mathbf{Z}/p^n \mathbf{Z}$ are finite and endowed with the discrete topology.) The non trivial thing is that a infinite product of compact (even finite discrete sets) is compact, the so-called Tychonoff theorem.
A: Show that the complement is open.
In particular, if $(x_1,x_2,\dots)\in \prod A_i\setminus \mathbb Z_p$ if any only if for some $n$, $\phi_n(x_n)\neq x_{n-1}$.
So, for each pair $a\in A_n$, define $$U_{a} = \pi_n^{-1}(\{a\})\cap\pi_{n-1}^{-1}(A_{n-1}\setminus\{\phi_n(a)\})$$
This is open (since $\{a\}$is open in $A_n$ and $A_{n-1}\setminus\{\phi_n(a)\}$ in $A_{n-1}$.)
Define $U = \bigcup_aU_a$, where the union is taking over for all $a$ in all $A_n$.
It is open because it is the union of open sets.
Then show that $U=\prod A_i\setminus \mathbb Z_p$.
