Your examples work nicely. Let $\mathbb{Z}_n$ be the cyclic group of order $n$. The following theorem is useful in looking at this sort of situation (taken from Contemporary Abstract Algebra by Gallian, 5th ed.):
Let $a$ be an element of order $n$ in a group and let $k$ be a positive integer. Then $\langle a^k\rangle=\langle a^{\gcd(n,k)} \rangle$ and $|a^k|=n/\gcd(n,k)$.
So how can we apply this? Well, clearly $1$ is an element of $\mathbb{Z}_n$ of order $n$. Then (now in additive notation to be consistent with the operation in $\mathbb{Z}_n$) $\langle k\cdot 1 \rangle = \langle k \rangle = \langle \gcd(n,k)\cdot 1 \rangle$, and so if $\gcd(n,k)=1$ then $\langle k \rangle = \langle 1 \rangle = \mathbb{Z}_n$.
This also follows by the second part of the theorem, by noting that $|\langle k \rangle |=|k|$. If $\gcd(n,k)=1$ then $|k|=\frac{n}{1}=n=|\langle k \rangle |$ so $k$ generates $\mathbb{Z}_n$. On the other hand, if $m=\gcd(n,k)\ne 1$ then $|k|=\frac{n}{m}=|\langle k \rangle |, so $k$ does not generate $\mathbb{Z}_n$ but rather a subgroup of order $\frac{n}{m}$.