If $ \int_0^{\pi}f(x)\cos(nx)\,dx=0$ for all $n$ then prove that $f\equiv 0$ 
If $f:[0,\pi]\to \mathbb R$ is continuous and $f(0)=0$ such that $\displaystyle \int_0^{\pi}f(x)\cos(nx)\,dx=0$ for all $n=0,1,2,\cdots$ then prove that $f\equiv 0$ in $[0,\pi]$.

I want to apply Weierstrass approximation theorem. As $f$ is continuous so there exists a sequence of polynomials $\{p_n(x)\}$ such that $p_n(x)\to f$ uniformly. If I expand $\cos nx=1+\frac{n^2x^2}{2!}+\cdots$ then $$\int_0^{\pi}f(x)\,dx+\frac{n^2}{2!}\int_0^{\pi}x^2f(x)\,dx+\cdots=0.$$which implies  $\displaystyle \int_0^{\pi}x^{2n}f(x)\,dx=0$ for each $n=0,1,2,\cdots$. Is this step correct ? If yes then I can deduce from it that $f\equiv 0$. If I am Not correct then solve it please.
 A: You can extend $f$ to $g$ on $[-\pi,\pi]$, s.t. $g(x)=f(-x)$ if $x<0$.
Then $\hat{g}(n)=\frac{1}{\pi}\int_0^\pi f(x)cos(nx)dx=0$ for all $n$. By Parseval's identity, $\int |g|^2=0$ which implies $f=0$.
A: (Complete revamp of my previous answer.)
Extend $f$ by $f(x) = f(-x)$ for $x \in [-\pi,0)$, then $f$ is $2\pi$ periodic
and so for any $\epsilon>0$ there is a trigonometric polynomial $q$ such that $\|f-q\|_\infty = \sup_{|x|\le \pi} |f(x)-q(x)| < \epsilon$.
(Recall that a trigonometric polynomial is of the form
$q(t) = a_0+\sum_{k=1}^n (a_k \cos(kt) + b_k \sin (kt))$). (See, for example,
Rudin's "Real & Complex Analysis", Theorem 4.25.)
Let $\tilde{q}(t) = {1 \over 2} (q(t)+q(-t))$ and note that
$\|f-\tilde{q}\|_\infty \le {1 \over 2} (\|f-q\|+ \|f-q\|) < \epsilon$ (where 
we used evenness of $f$ for the last part). Hence we may assume that $q$ is
even to begin with, in particular, $q$ has the form
$q(t) = a_0+\sum_{k=1}^n a_k \cos(kt) = \sum_{k=0}^n a_k \cos(kt)$.
Note that, by assumption, $\int_{-\pi}^\pi f(x) q(x) dx = 0$.
Then $\int_{-\pi}^\pi f^2(x) dx = \int_{-\pi}^\pi f(x) (f(x)-q(x)+ q(x)) dx = \int_{-\pi}^\pi f(x) (f(x)-q(x)) dx$, hence
$\int_{-\pi}^\pi f^2(x) dx \le \|f\|_\infty 2 \pi \epsilon$. Since
$\epsilon>0$ was arbitrary, we see that $\int_{-\pi}^\pi f^2(x) dx = 0$. Since
$f$ is continuous, and $f^2(x) \ge 0$ for all $x$ we see that
$f(x) = 0$ for all $x$.
A: Extend $f$ to be even on $[-\pi,\pi].$ We then have
$$\hat f (n) = \frac{1}{2\pi}\int_{-\pi}^\pi f(x)e^{-inx}\,dx = \frac{1}{\pi}\int_{0}^\pi f(x)\cos (nx)\,dx = 0$$
for all $n\in \mathbb {Z}.$  Thus $$\frac{1}{2\pi}\int_{-\pi}^\pi|f|^2 = \sum |\hat f (n)|^2 = 0.$$
This implies $f\equiv 0.$ I did not use the condition $f(0)=0,$ which makes me think the problem should have been stated assuming $\int_0^\pi f(x)\sin (nx)\, dx =0, n=1,2,\dots.$
