Largest subgroup of rank $k$ of an abelian group of rank $r$ If $G$ is a finite abelian group of rank $r$ with invariant factorization
$$G\cong\mathbb{Z}_{n_1}\times\cdots\times\mathbb{Z}_{n_r},$$
I'm trying to show that the largest subgroup of $G$ with rank $k$ is the group
$$ H=\mathbb{Z}_{n_{r-k+1}}\times\cdots\times\mathbb{Z}_{n_r}.$$
This is clearly the largest subgroup with rank $k$ that is a subproduct, but since there are other subgroups that are not subproducts, I don't know how to prove this. A proof would be appreciated.
 A: I'm going to interpret what you want to prove as follows: (by "rank" I understand you mean "size of minimal generating set"; I usually use "rank" in the context of finitely generated abelian groups to refer to the dimension of the torsionfree part...)

Let $G=\mathbb{Z}_{n_1}\oplus\cdots\oplus\mathbb{Z}_{n_r}$ be a finite abelian group of rank $r$, $n_1|\cdots|n_r$. Then the largest subgroup of $G$ of rank $k\leq r$ is isomorphic to $\mathbb{Z}_{n_{r-k+1}}\oplus\cdots\oplus\mathbb{Z}_{n_r}$.

(Note the "isomorphic to"; because there are multiple subgroups of $G$ of that form)
It will be easier to do this for $p$-groups first. Let
$$G=\mathbb{Z}_{p^{a_1}}\oplus\cdots\oplus\mathbb{Z}_{p^{a_r}}$$
with $a_1\leq\cdots\leq a_r$. Let $n=a_1+\cdots+a_r$, $|G|=p^n$; we do induction on $n$. The result is immediate if $n\leq 1$, so we may assume $n\gt 1$. Note that the result is also immediate if $a_r=1$, so in what follows I will be tacitly assuming that $a_r\gt 1$.
Assume the result holds for abelian $p$-groups of smaller size. Let
$H$ be a subgroup of rank $k$ of largest possible order; if $k=0$ there is nothing to prove, so we may also assume $1\leq k\leq r$.
I claim that $H$ must contain an element of order $p^{a_r}$.
Indeed, let $j$ be the smallest index with $a_j=a_r$, and let  $\pi_i\colon G\to\mathbb{Z}_{p^{a_i}}$ is the projection onto the $i$th component. If $H$ has no elements of order $p^{a_r}$, then $\pi_i(H)$ is a proper subgroup of $\mathbb{Z}_{p^{a_i}}$ for $j\leq i\leq r$. Thus, $H$ can be realized as a subgroup of
$$\mathbb{Z}_{p^{a_1}}\oplus\cdots\oplus\mathbb{Z}_{p^{a_{j-1}}}\oplus p\mathbb{Z}_{p^{a_j}}\oplus\cdots\oplus p\mathbb{Z}_{p^{a_r}};$$
which is isomorphic to $$\mathbb{Z}_{p^{a_1}}\oplus\cdots \oplus\mathbb{Z}_{p^{a_{j-1}}}\oplus \mathbb{Z}_{p^{a_{j}-1}}\oplus\cdots\oplus\mathbb{Z}_{p^{a_r-1}}.$$
But this is an abelian $p$-group of order $p^{n-(r-j+1)}$, and so by the induction hypothesis we know that $H$ has the described form; but this group has order strictly smaller than $p^{a_{r-k+1}+\cdots+a_r}$, and hence cannot be a subgroup of largest possible order in our original $G$, a contradiction.
Thus, $H$ contains an element of order $p^{a_r}$; call it $h_r$. Now $h_r$ is an element of largest possible order in $G$; therefore, there exists a subgroup $G'\leq G$ such that $G\cong G'\oplus \langle h_r\rangle$. See for example here. Note that by the Structure Theorem for finitely generated abelian groups, know that
$$G' \cong \mathbb{Z}_{p^{a_1}}\oplus\cdots\oplus\mathbb{Z}_{p^{a_{r-1}}}.$$
Let $H'=H\cap G'$. I claim that $H=H'\oplus\langle h_r\rangle$. Indeed, if $h\in H$, then we can write $h=g'+kh_r$ for some $g\in G'$; since $h_r\in H$, then $g' = h-kh_r\in H$, so $g'\in H'$. Thus, $h\in H'+\langle h_r\rangle$. And since $G'\cap\langle h_r\rangle=\{0\}$, then $H'\cap\langle h_r\rangle = \{0\}$.
I claim that $H'$ is a subgroup of rank $k-1$ and largest possible order in $G'$ (which has rank $r-1$). Indeed, the rank of $H'$ follows from the rank of $H$ and the structure theorem; and for any subgroup $K$ of $G'$ of rank $k-1$, $|K|+p^{a_r} = |K\oplus\langle h_r\rangle| \leq |H| = |H'|+p^{a_r}$, hence $|K|\leq |H'|$.
We can now apply induction to $H'$ and $G'$, seeking the largest possible subgroup of rank $k-1$; by induction, this will be isomorphic to
$$\mathbb{Z}_{p^{a_{(r-1)-(k-1)+1}}}\oplus\cdots\oplus\mathbb{Z}_{p^{a_{r-1}}}.$$
Hence
$$H = H'\oplus\langle h_r\rangle \cong \mathbb{Z}_{p^{a_{r-k+1}}}\oplus\cdots\oplus\mathbb{Z}_{p^{a_{r-1}}}\oplus\mathbb{Z}_{p^{a_r}},$$
as desired.

For the general case, we can use the result for $p$-groups on the $p$-parts separately; if a $p$-part has rank strictly smaller than $k$, then we will clearly "grab" the whole $p$-part. At least one $p$-part has rank $r\geq k$. And the way that the invariant factors are constructed from the primary divisors shows that the case for $p$-groups implies the general case.
The main reason to do the $p$-group case first is that it is easier to describe why the element of largest order in $H$ must be of order $p^{a_r}$; otherwise, it becomes a bit complicated to express the decomposition of the proper subgroup containing $H$.
