Find a function $f$ with given criterion Please help me to find a function with a given criterion. 
I need a non-negative function $f(x)$ such that


*

*$\lim\limits_{x \rightarrow \infty }f(x) $ does not  exists

*$\int\limits_0^{\infty}f(x)\ dx$ exists
I don't know whether such a function exist.
I have tried several function but none of them suit.  If no such function exist then please help me to sketch a proof.
 A: The typical example is to let $f$ be mostly $0$, but have narrower and narrower, evenly spaced spikes from $0$ to $1$ and back to $0$ again as $x\to \infty$. The narrowness of the spikes lets the integral converge, but stops $f$ from having a limit.
A: Consider the popcorn function/Thomae's function, which is defined on $[0,1]$.  This has Riemann integral $0$, and is discontinuous only on the rationals.  Make a copy of this on the higher intervals, e.g., $[1,2]$, $[2,3]$, $\dots$, $[n, n+1]$.  Then, clearly, $f$ is non-negative, and $\lim \limits_{x \to \infty} f(x)$ doesn't exist (why?), and $\int \limits_{0}^{\infty} f(x)\,dx = \sum \limits_{n = 0}^{\infty} \int \limits_{n}^{n + 1} f(x)\,dx = \sum \limits_{n = 0}^{\infty} 0 = 0$.
EDIT: By the way, based on your answer history it looks like you proved Thomae's function is continuous on the irrationals, so it looks like you have some experience with this example.
A: Here's a real-analytic example:
$$f(x) = \left (\frac{2+\cos x}{3}\right )^{x^3}.$$
The function inside the parentheses equals $1$ at the points $2n\pi, n = 0,1,2,\dots$ Everywhere else it takes values in $[1/3,1).$ The exponent $x^3$ grows rapidly and smashes the thing down close to $0$ at a fast enough rate to lead to a convergent integral. (Why $x^3?$ It has something to do with Laplaces's method.)
I include this just for fun. Triangular spikes are the way to go for intuition.
A: Take $f:[0, + \infty) \rightarrow [0, + \infty)$ such that $f(x)=x$ if $x \in \mathbb{N}$ and $f(x)=0$ if $x \notin \mathbb{N}$
Also note the $f(x)$ is non-negative.
We have that the limit if $f(x)$ as $x \rightarrow + \infty$ does not exist.
From Lebesgue's theorem, $f$ is Riemman integrable because is discontinuous in a countable set and every countable set has measure zero.
A set $A$ has measure zero if  $\forall \epsilon>0$ exist a sequence of open intervals $(a_n,b_n)$ such that  $A \subseteq \bigcup_{n=1}^{\infty}(a_n,b_n)$ such that $\sum_{n=1}^{\infty}(b_n-a_n) \leqslant \epsilon$
Now  $\int_0^{\infty}f(x)= \sum_{k=1}^{\infty} \int_{k-1}^kf(x)dx$
The O.P as an exercise he/she can prove that $\int_{k-1}^kf(x)dx=0, \forall k \in \mathbb{N}$ and conclude that $\int_0^{\infty}f(x)dx=0$
