there is a function f(x) which is continues
and every rational number "r" is its period of f(x)
prove that f(x)=const
??
First let us establish a lemma. If $\displaystyle f$ is continuous at $\displaystyle c$ then there exists a neighborhood $\displaystyle (c-\delta,c+\delta)~~\delta>0$ such that for any $\displaystyle x_1,x_2\in (c-\delta,c+\delta)$ the following must be true, $\displaystyle |c-x_1|<|c-x_2|\implies|f(c)-f(x)|\leqslant|f(c)-f(x_1)|$.
Proof: Suppose the above is false, so that for any neighborhood of $\displaystyle c$ there exists points $\displaystyle x_1,x_2$ in that neighborhood such that $\displaystyle |x_1-c|<|x-c_2|$ and $\displaystyle |f(c)-f(x_1)|>|f(c)-f(x_2)|{\color{red}(*)}$. It is clear then from $\displaystyle \color{red}(*)$ that $\displaystyle |f(c)-f(x_1)|$ may be written as $\displaystyle |f(c)-f(x_2)|+e~~e>0$. So now in the definition of continuity choose $\displaystyle \varepsilon=|f(c)-f(x_1)|+d~~0<d<e$ so there must exist a $\displaystyle \delta>0$ such that $\displaystyle |x-c|<\delta\implies |f(c)-f(x)|<\varepsilon$ but this is a conradiction since $\displaystyle |c-x_1|<|c-x_2|<\delta$ but $\displaystyle |f(c)-f(x_1)|=|f(c)-f(x_2)|+e>\varepsilon$
So now back to the problem. Let us talk about our function on an interval $\displaystyle [a,b]$. Let $\displaystyle c\in[a,b]$ and $\displaystyle f(c)=\xi$. So by the above lemma we must have that there is an interval such that $\displaystyle |c-x_1|<|c-x_2|\implies |\xi-f(x_1)|\leqslant|\xi-f(x_2)|$ with $\displaystyle x_1,x_2$ elements of that interval. Now let $\displaystyle x_2=c\pm r~~r\in\mathbb{Q}\implies f(x_2)=\xi$. So we must then have that $\displaystyle |c-x_1|<|c-x_2|\implies |f(c)-f(x_1)|\leqslant |\xi-\xi|=0$ or that $\displaystyle f(x_1)=\xi$. So for any point of $\displaystyle [a,b]$ there is a neighborhood such that $\displaystyle f=\xi$, thus we must have that $\displaystyle f=\xi~~\forall x\in[a,b]$
Note: I forgot to mention one important fact...this construction is possible that since no matter how small the neighborhood in question is it must contain at least one rational
This lemma somehow tells that a continuous function is locally monotonous. This fails to be true... Think of $\displaystyle x\mapsto x\sin\frac{1}{x}$ for instance, at 0. It is continuous and it oscillates so the conclusion of the lemma can't be satisfied. The problem in the proof comes from the fact that there is no reason why $\displaystyle x_1,x_2$ would be in $\displaystyle [c-\delta,c+\delta]$. ($\displaystyle \delta$ is defined given $\displaystyle x_1,x_2$)
There's much simpler (and correct): notice that for any rational $\displaystyle q$, since $\displaystyle f$ is $\displaystyle q$-periodic, $\displaystyle f(q)=f(0)$. In other words, $\displaystyle f$ is constant on $\displaystyle \mathbb{Q}$. Let's say $\displaystyle f(0)=c$. Now, let $\displaystyle x$ be any real number, rational or not. It is well known that there exists a sequence $\displaystyle (q_n)_n$ of rational numbers that converges toward $\displaystyle x$. Since $\displaystyle f$ is continuous, we conclude $\displaystyle f(x)=\lim_n f(q_n)=c$ (the sequence $\displaystyle (f(q_n))_n$ is constant, equal to $\displaystyle c$). qed.
Once I was asked a question by my professor in real analysis lesson, now I feel that it is very similar to this problem.
Let $\displaystyle f$ be a continuous function, if $\displaystyle f$ is of fixed value at irrational numbers, then $\displaystyle f$ takes that fixed value on rational numbers too, and hence it is a constant function.
Uh, but $\displaystyle f:x\mapsto x\sin\left(\frac{1}{x}\right)$ is not continuous at zero. And I think I stated my Lemma wrong. It was meant to be that there exists a neighborhood of c such that there is a subset of that neighborhood that such that the above is true. Supposing that this suffices it still shows the result of the question and I believe it works for your example.
Sorry Opalg and transgalactic for the fallacious proof. I always make things harder than they are. How about this alternate proof (this is more for my curiosity then for the OP)
Suppose the claim is true and $\displaystyle f$ is constant. We must merely show that $\displaystyle f$ is differentiable everywhere and $\displaystyle f'=0$, in other words for all $\displaystyle x$ we must show that $\displaystyle \lim_{t\to x}\frac{f(t)-f(x)}{t-x}=0$. But now consider letting $\displaystyle t=x+ r~~r\in\mathbb{Q}$. So the above is equivalent to showing $\displaystyle \lim_{r\to{0}}\frac{f(x+r)-f(x)}{r}=0$ but $\displaystyle f(x+r)=f(x)$ so $\displaystyle \frac{f(x+r)-f(x)}{r}=0$ which finally in turn implies $\displaystyle \lim_{r\to0}\frac{f(x+r)-f(x)}{r}=0$
Just for your curiosity . There is one step that would require a justification: if $\displaystyle \lim_{r\to{0},\ r\in\mathbb{Q}}\frac{f(x+r)-f(x)}{r}$ exists, why would $\displaystyle \lim_{r\to{0}}\frac{f(x+r)-f(x)}{r}$ exist as well? This is quickly proved from the definition of the limit (cf. right below), but I think it should be underlined since this is where the continuity is needed, and thus this is the core of the proof.
Suppose that a continuous function $\displaystyle \psi$ on $\displaystyle \mathbb{R}\setminus\{0\}$ is such that $\displaystyle \lim_{r\to 0,\ r\in\mathbb{Q}} \psi(x)=\ell$. Let $\displaystyle \varepsilon>0$. There is $\displaystyle \delta>0$ such that if $\displaystyle |r|<\delta$ and $\displaystyle r\in\mathbb{Q}\setminus\{0\}$ then $\displaystyle |\psi(r)-\ell|\leq \varepsilon$. Now, if $\displaystyle |x|< \delta$ and $\displaystyle x\neq 0$, $\displaystyle x$ is a limit of non-zero rational numbers $\displaystyle r_n$ with $\displaystyle |r_n|<\delta$, so that $\displaystyle |\psi(x)-\ell|=\lim_n |\psi(r_n)-\ell|\leq \varepsilon$ (since this inequality holds for every $\displaystyle n$). This proves that $\displaystyle \lim_{x\to 0}\psi(x)=\ell$.
Of course I could be wrong so wait for Laurent or another senior member's confirmation, but what I think Laurent's solution points to is that if $\displaystyle f:X\longmapsto\mathbb{R}$ with $\displaystyle X\subset\mathbb{R}$ then $\displaystyle \lim_{x\to p}f(x)=q\Longleftrightarrow \lim_{n\to\infty} f(p_n)=q$ for all $\displaystyle p_n\subset X$ and $\displaystyle p_n\to p\qquad p_n\ne p$. Now using this result every number rational or irational is the limit of a sequence of rationals.
I'm not sure I get what you mean.
In the proof, I wrote "Let $\displaystyle x$ be (...)" so that, from this point on, $\displaystyle x$ is fixed, you can think of it as a constant, and I am allowed to introduce a sequence converging to $\displaystyle x$. More specifically, I use the fact that any real number (hence for instance, $\displaystyle x$) is the limit of a sequence of rational numbers. Finally, since I chose $\displaystyle x$ to be any number, what I prove for $\displaystyle x$ holds for any number.