Theorem: Let $K$ be a subset of $\mathbb{R}.$ If $f(K)$ is bounded for any continuous function $f:K\to\mathbb{R}$, then $K$ must be compact.
The same theorem, written in quants: $\forall f\in C(K): $ $f(K)$ is bounded in $\mathbb{R}$ => $K$ is compact.
$K$ is a subset of $\mathbb{R}$, $C(K)$ is the set of all continuous functions defined on $K$
I have seen other solutions, but they use too advanced a level for me. Can you give a proof of this theorem, referring only to results not beyond introductory real analysis?
P.S. Thank you for your time!
We work by contradiction. We take as our hypothesis that every continuous function on $K$ is bounded. We assume $K$ is not bounded and demonstrate a contradiction. Then we assume that $K$ is not closed and demonstrate another contradiction.
As noted above, if $K$ is unbounded, the identity function on $K$ also is unbounded.
If $K$ is not closed, then $A=\Bbb R \setminus K$ is not open. Choose $x \in A$ such that there is no open ball around $x$ that is contained in $A$. Such an $x$ must exist because $A$ is not open. That means every open ball around $x$, no matter how small, has non-empty intersection with $K$, so you can get as close as you like to $x$ and still stay within $K$.
Then $f: K \to \Bbb R$ defined by $f(y)= \dfrac{1}{y-x}$ is continuous and unbounded on $K$. The function $f$ is continuous on $K$ because it's continuous on $\Bbb R \setminus \{x \}$ and $x \in A \Rightarrow x \notin K$ by the definition of $A$, so $K \subseteq \Bbb R \setminus \{ x \}$. It's unbounded because we just showed that we can make $\vert y - x \vert$ arbitrarily small and still stay within $K$, which means we can make $\vert f(x) \vert =\left \vert \dfrac{1}{y-x} \right \vert$ arbitrarily large within $K$.
In higher dimensions, use the function $\dfrac {1}{d(y, x)}$ to the same effect.
Thus, if all continuous functions on $K$ are bounded, it follows that $K$ must be closed and bounded; in other words, compact.