Prove that $\lim_{x\to\infty} \frac{1}{x}\int_0^xf(t)dt$ exists and find it, where $f(t)$ is an alternating function. The problem: function $f$ alternates between $1$ and $-1$ on $[0^2; 1^2), [1^2; 2^2), ... [(n-1)^2; n^2)$, so on $[0^2; 1^2], \;f(x) = 1;$ on $[1^2; 2^2],\;f(x) = -1$ etc. 
Prove that $\;\;\lim_{x\to\infty} \frac{1}{x}\int_0^xf(t)dt\;\;$ exists and find it.
What I did: 

Questions: Where did I go wrong? I honestly don't believe this limit exists but it says so in the problem statement so I don't even know. I tried doing it without the $x \in \mathbb N$, but I get the same result: The limit can't exist because the value alternates between $1$ and $-1$. Thank you!
 A: To fix your reasoning: The length of the $n$-th interval is $n^2 - (n - 1)^2 = 2n - 1$. Assume $x = n^2$, where $n \in \mathbb{N}$.
\begin{align}
\lim_{x \to \infty} \frac{1}{x} \int_0^x f(t) \, \mathrm{d}t &= \lim_{n \to \infty} \frac{1}{n^2} \int_0^{n^2} f(t) \, \mathrm{d}t \\
&= \lim_{n \to \infty} \frac{1}{n^2} \sum_{k = 1}^n (-1)^{k+1} (2k - 1) \\
&= \lim_{n \to \infty} \frac{1}{n^2} (-1)^{n+1} n \\
&= 0.
\end{align}
A: Let $x \in \mathbf R$. Then there is a unique integer $n \in \mathbf N$ such that $n^2 \le x < (n+1)^2$. We have 
\begin{align*}
  \int_0^x f(t)\, dt &= \sum_{k=0}^{n-1} (-1)^k (2k+1) + (-1)^n(x-n^2)\\
    &= 2\sum_{k=0}^{n-1} (-1)^k k + \frac 12\bigl(1 + (-1)^{n}\bigr) + (-1)^n(x-n^2)\\
    &= \frac 12\bigl((-1)^{n-1}2n - 1\bigr) + \frac 12\bigl(1+(-1)^n\bigr) + (-1)^n(x-n^2)\\
\end{align*}
Dividing by $x$ now (note that $x \sim n^2$, this was your main mistake, if you let $x \in \mathbf N$, that is fine, but the sum goes up to $\sqrt x$ then, only), we have 
\begin{align*}
  \def\abs#1{\left|#1\right|}\abs{\frac 1x \int_0^x f(t)\, dt}
  &\le \frac 12 \frac{2n + 1}x + \frac 1x + \frac{x-n^2}x
\end{align*}
Now $x-n^2 \le (n+1)^2 - n^2 = 2n+1$ and $\frac 1x \le \frac 1{n^2}$ as $n^2\le x$. Hence 
\begin{align*}
   \abs{\frac 1x \int_0^x f(t)\, dt} &\le \frac 32 \frac{2n +1}{n^2} + \frac 1{n^2}
\end{align*}
Now $n \to \infty$ for $x \to \infty$, that is the above converges to $0$, therefore 
$$ \frac 1x \int_0^x f(t)\, dt \to 0, \qquad x \to \infty $$
