TITLE: Proving $K$ is compact directly.
QUESTION [5 upvotes]: If $K$ is a subset of metric space $\mathbb{R}^n$ and if every real valued continuous function on $K$ is bounded,  then $K$ is compact.

I know a proof considering $K$ is unbounded and not closed. This is proof by contradiction.

Is there any direct way to prove?

Please help!

REPLY [2 votes]: Suppose that $U_n$ is a sequence of open sets that cover $(X,d)$.  Let
$$ f(x) = \sum_{n=1}^\infty 2^{-n} \min\{d(x,U_n^C),1\} .$$
We know $f(x) > 0$ for $x \in X$.  So by hypothesis, $1/f$ is bounded above by $2^{N-1}$ for some $N \in \mathbb N$.  Hence $f(x) > 2^{-N}$ for all $x\in X$, and so $X \subset \bigcup_{n=1}^N U_n$.
This shows every countable cover has a finite subcover.
Not sure how to complete it.