Prove $f$ is uniformly continuous iff $ \lim_{x\to \infty}f(x)=0$ 
Let $f:[0,\infty)\to (0,\infty)$ be a continuous function and $\displaystyle\int^{\infty}_{0}f<\infty$. Show that $f$ is uniform continuous iff $\displaystyle\lim_{x\to \infty}f(x)=0$

So I could only see that continuity is not sufficient condition for the limit to exists since $\displaystyle\int^{\infty}_{0} \cos x^2$ exists but $\displaystyle\lim_{x\to \infty}\cos x^2$ does not exist , so we need something more stronger than continuity. 
 A: Hint: If $f$ does not approach zero at infinity, there is an $\varepsilon>0$ and a sequence $x_n\to\infty$ so that $f(x_n)>2\varepsilon$ for each $n$. If $f$ is uniformly continuous, there is $\delta>0$ so that $|x-y|<\delta$ implies $|f(x|-f(y)|<\varepsilon$. Now look at what that says about $f$ near the points $x_n$.
Edit: I should say something about the reverse direction. Assume $f\to0$ at infinity. If $\varepsilon>0$ is given, that means there is $M$ so that $x>M$ implies $f(x)<\varepsilon$. Now use the uniform continuity of $f$ on the compact interval $[0,M]$.
A: When $f$ is merely continuous, we can make $f$ be a sequence of disjoint triangles of a fixed height, say $1$, and a decaying width, say $1/(2n^2)$. Then the integral of $f$ is $\sum_{n=1}^\infty 1/(4n^2)<\infty$, but there are arbitrarily large points where $f$ is $1$. We can make this even worse; for example we can make the heights $n$ and the widths $1/(2n^3)$, and then $f$ isn't even bounded. We can repeat this argument with your constraint that the codomain is $(0,\infty)$ in a number of ways. For example, we can make the $n$th triangle start at $1/(2n^2)$, rise to $1$, then fall to $1/(2(n+1)^2)$, then stay there until the $(n+1)$th triangle begins to rise, etc.
The problem here is that the triangles are allowed to shrink in width even as they stay the same size in height. When $f$ is uniformly continuous, this is impossible: if there are arbitrarily large points where $f>\varepsilon$, then there are infinitely many disjoint intervals of a fixed width $\delta$ where $f>\varepsilon/2$. From this we conclude $\int_0^\infty f(x) dx \geq \sum_{n=1}^\infty \varepsilon \delta/2 = \infty$.
