Let $I$ be an interval and let $f$ : $I \rightarrow\mathbb{R}$ be a function. If $f$ is monotonically increasing as well as monotonically decreasing on $I$, then show that $f$ is constant on $I$.
My approach: Consider $x,y\in I$ such that $x\neq y$. Assume that $x>y$. Since $f$ is monotonically increasing on $I$, so $f(x)\geq f(y)$. Also $f$ is monotonically decreasing on $I$. Thus we have $f(x)\leq f(y)$. Hence $f(x)=f(y)$. But from here how I can show that $f$ is constant on $I$?