Suppose $f(x)$is a continuous function on $[0,1]$ such that $f(x)=x$, when $x$ is irrational in $[0,1]$. Show that $f(x)=x$ for all $x \in [0,1]$ 
Suppose $f(x)$is a continuous function on $[0,1]$ such that $f(x)=x$, when $x$ is irrational in $[0,1]$. Show that $f(x)=x$ for all $x \in [0,1]$

I understand that this is due to denseness property. But I don't know whether Intermediate Value Theorem is application to prove it. Please help me.
 A: Given a rational $q\in[0,1]$, there exist a sequence $\{r_n\}\subset\mathbb{R}-\mathbb{Q}$ such that $r_n\rightarrow q\text{ as }n\rightarrow\infty$.
Recall the definition of continuity of a function via "convergence of sequence".
I hope you can do it now! 
A: Suppose $S$ is any set of reals
that is dense in $[0, 1]$.
Suppose $x \in [0, 1]-S$.
Since $S$ is dense,
there are a sequence
$(a_i)_{i=1}^{\infty}$
such that
$a_i \in S$
and
$\lim_{i \to \infty} a_i = x$.
Suppose $f(x) \ne x$.
Then $f(x)-x \ne 0$.
Let $d = |f(x)-x|$.
Since $f$ is continuous,
there is a neighborhood
$[x-c, x+c]$ of $x$
such that
$|y-x| < c
\implies |f(y)-f(x)| < d/2
$.
Since
$a_i \to x$,
there is an $n$ such that
$|a_n-x| < c$.
For this $n$
$|f(a_n)-f(x)| < d/2
$
so
$-d/2 < f(a_n)-f(x) < d/2$
or
$f(a_n)-d/2 < f(x) < f(a_n)+d/2$.
Since $f(a_n) = a_n$,
this implies
$a_n-d/2 < f(x) < a_n+d/2$.
Since
$x-c < a_n < x+c$,
$x-c-d/2 < f(x) < x+c+d/2$,
so
$|f(x)-x| < c+d/2$.
This is a contradiction
if we choose $c < d/2$.
A: You ask if it can be proven with Intermediate Value theorem.  Let's see...
If $f(c)= d; d\ne c;c \in \mathbb Q; d$ maybe irrational maybe not.  Wolog assume $d > c$ and let $\epsilon = d-c$.  So there is and irrational $y \in [c,d]$ so that $f(y) = y < d < f(c)$.  Let $K = \{x > c|x \not \in \mathbb Q; f(x) < f(c)\}$.  That set is non-empty and bounded below by $c$ so $w = \inf K$ exists.
Okay, as $f$ is continuous $f(w) = \inf f(K)$ and if $w > c$ then by intermediary value theorem for any $x; f(w) < x< f(c)$ there is a $y; c < y <w$ so the $f(y) = x$ so $y \in K$ which contradicts $w = \inf K$.  So $c = \inf K$.
But that means $f(c) = \inf f(K)$ and $f(K) = K$ as $K \subset \mathbb C^c$.  So $f(c) = c$.
Okay... that barely used the IMT.  But it did use it.  But it wasn't necessary. (We could have just defined $K = \{x > c\}$ and get the same result.)  In fact I think it just made things harder.
