How to introduce $p$-adic numbers to undergraduates? I want to introduce $p$-adic numbers to some undergraduate students. Assume they don't know much about number theory except elementary one. Since they already know metric space so the following analytic contruction would be easier to them:

*

*Analytic Construction- The field of rational numbers $\mathbb Q$ is not complete. Given a nonzero rational number $x \in \mathbb{Q}$, it can be expressed as $x=\frac{a}{b}p^n$ for $a,~b(\neq 0) \in \mathbb Z$. Then for each prime $p$, we can define the absolute value $|.|_p$ by $$|x|_p=p^{-n},$$ which is called $p$-adicx absolute value in contrast to usual absolute value. This $p$-adic absolute value defines a metric $d(x,y)$ given by $$d(x,y)=|x-y|_p~ \forall x,y \in \mathbb Q.$$
Now complete $\mathbb Q$ with respect to the metric $d(x,y)$ to obtain the field $\mathbb Q_p$, called $p$-adic number field.

This ananlytic construction is easier to follow.
But I want to show the algebraic construction as well.

*

*Algebraic Construction- Let $p$ be a prime. Then we will at first construct something smaller than $\mathbb Q_p$ i.e., the set of $p$-adic intergers denoted $\mathbb Z_p$. An element of $\mathbb{Z}_p$ is an infinite tuple $(a_i)_{i \in \mathbb N}$, where $a_i \in \mathbb Z/p^i \mathbb Z$. However we only consider those tupples which are compatible with the natural projection map $$\mathbb Z/p^i \mathbb Z \to \mathbb Z/p^j \mathbb Z,~~i \geq j.$$ Right here we have a filtration of congruences mod $p^i$ for all $i$. I am not sure how to explain it well enough but I am quite sure I need to explain about th solutions of the congruence relations like $$x^2 \equiv a~ (\mod ~p^n)$$ in the flavor of Newton-Raphson method. May be you can help me here.
For example, let $p=5$ and suppose we have the congruence relation $$x^2 \equiv -1~(\mod ~5),$$ in other words,  we are trying to find square root of $-1$ inside the $5$-adic integers $\mathbb Z_5$.  This has solution $2$ and $3$. Take $b_0=2$ as the solution and now we want to refine it to be more closer to square root of $-1$. So we consider the next congruence relation $$(2+5k)^2 \equiv -1(\mod ~5) ~i.e.,~x^2 \equiv -1 (\mod ~5^2),$$ which has solution $b_1=7$. In this way, we can continue as long as we want to refine the solution at each step, producing  the following $5$-adic expansions:
\begin{align}
 &x_0=2, \\
&x_1=2+7 \cdot 5, \\
& x_2=2+2 \cdot 5+b_0 \cdot 5^2,~ (0 \leq b_0 <5) \\
& x_3=2+2 \cdot 5+b_0 \cdot 5^2+b_1 \cdot 5^3, ~(0 \leq b_0,b_1<5), \\
& \cdots
\end{align}
So the sequence $\{x_n\}$ converges $5$-adically to square root of $-1$. Anyway, we have the $p$-adic integers $\mathbb Z_p$. Now this holds the property of an integral domain and so we can take the fraction field of $\mathbb Z_p$. It turns out that $\mathbb Q_p=\text{Frac}(\mathbb Z_p)$.

This is something about the algebraic construction.
I would appreciate if you improve my concept on algebraic construction of the $p$-adic numbers, specially the congruence part. Because the congruence $x^2 \equiv a(\mod p^n)$ might not have solution. I expect some better answer than the above.
What was the main motivation of Kurt Hensel ? Did he want to solve the congruence equation $x^m \equiv a (\mod p^n)$ which led him to $p$-adic numbers?
 A: Several years ago, I directed an informal undergraduate reading course on $p$-adic numbers. We followed Neal Koblitz's book $p$-adic Numbers, $p$-adic Analysis, and Zeta-Functions (GTM volume 58). I really like the way this book presents the subject, and the students had a similar level of background to what you describe and found the book to be at an appropriate level, so it's worth considering this book if you want a written reference for the course.
Koblitz presents the $p$-adic numbers primarily through the analytic construction. The algebraic construction of the $p$-adic integers isn't explicitly introduced in those terms, but the essence of it is contained in the following theorem that Koblitz proves in chapter 1:

Theorem 2. Every equivalence class $a$ in $\mathbb{Q}_p$ for which $\lvert a \rvert_p \leq 1$ has exactly one representative Cauchy sequence of the form $\{a_i\}$ consisting of integers such that $0 \leq a_i < p^i$ and $a_i \equiv a_{i+1} \pmod{p^i}$ for all $i$.

The proof of this theorem is followed by a discussion of $p$-adic expansions. I don't think Koblitz explicitly describes this as a separate construction using the language of abstract algebra (that is, viewing these integers as elements of $\mathbb{Z}/p^i\mathbb{Z}$), but you could add it as a remark that immediately follows from that theorem and the discussion afterward.
In other words (whether or not you use this book), I would suggest using the analytic construction to prove the existence and basic properties of $p$-adic expansions of $p$-adic numbers first (and to favor the representation of $p$-adic expansions using sequences of integers rather than sequences of residue classes of integers), and only afterwards remark that in fact one could use this as an alternative algebraic construction of the $p$-adic numbers.
This is actually fairly consistent with Hensel's original motivation, which was to explore the analogy between power series in function fields (e.g. Taylor series of complex-analytic functions at a point) and power series in number fields (that is, "$p$-adic expansion of an algebraic number"), and to use this to prove theorems in algebraic number theory. The concept of a $p$-adic expansion is central. See here for some references on the history of the $p$-adic numbers.
