An explanation of the formula for the present value of an annuity
Take your second statement: $\dfrac{x}{r}$ is the present value of a perpetuity paying $x$ starting from now (first payment in year $1$)

Now consider the present value of a perpetuity paying $x$ with first payment in year $n+1$.  This is the value in year $n$ of $\dfrac{x}{r}$, discounted back to now so dividing by $(1+r)^n$ to give $\dfrac{x}{(1+r)^n r}$

So the present value of an annuity paying $x$ for the first $n$ years is the difference between these, namely $\dfrac{x}{r}-\dfrac{x}{(1+r)^n r}$



An alternative approach would be to consider the sum of the present values of the $n$ payments $$S= \dfrac{x}{(1+r)} + \dfrac{x}{(1+r)^2} + \cdots + \dfrac{x}{(1+r)^{n}}$$ and you might calculate this using the following to allow cancelation  $$(1+r)S - S = x -  \dfrac{x}{(1+r)^n}$$ which since $(1+r)S-S=rS$ becomes $$S=\dfrac{x}{r}-\dfrac{x}{(1+r)^n r}$$

It may be worth noting that the second term tends to zero if $n$ increases, so the value or cost of a long-term annuity approaches that of a perpetuity