If $f \in C[0, \pi]$ and $\int_0^\pi f(x) \cos nx\, \text{d}x = 0$ , then $f = 0$
Define $ g(x) = \begin{cases} f(-x) & \text{if } -\pi \leq x < 0;\\ f(x) & \text{if } 0 \leq x \leq \pi. \end{cases}$
which is an even function
So $g(x)$ can be written as $\sum_{n=0}^\infty a_n\cos (nx)$ for all $x \in [-\pi , \pi]$
$$\therefore \int_0^\pi f^2(x) \, dx = \int_0^\pi f(x) \left(\sum_{n=0}^\infty \cos(nx)\right) \, dx = \sum_{n=0}^\infty \int_0^\pi f(x) \cos(nx) \, dx = 0$$
$$\therefore \int_0^\pi f^2(x) \, dx =0,$$ we get $f(x) = 0$
I think this part is my true
$$\text{If }f \in C[0 , \pi] \text{ and } \int_o^\pi x^n f(x) \, dx = 0 \text{ for all } n\geq0, \text{ then } f = 0$$
Since $f$ is continous on a closed interval, then by stone Aproximation Theoren , for each $\epsilon > 0$ , there is a polynomial $p(x)$ such that $|f(x) - p(x)| < \epsilon$.
I want to show that $\int_0^\pi f(x) \, dx = 0$, please help me how to proceed further and check the first part. Any help would be appreciated.
I am usually too lazy to critique answers even when the OP asks for it. It is easier to just snipe with a comment or two. But @zhw has shamed me into really looking at the answer and maybe offering a bit of a tutorial. Since I gave a sloppy comment I will make amends here I hope.
Here some things that you know or should know judging from the title of the problem and your answer.
A continuous even function $f$ on $[-\pi,\pi]$ has a Fourier series of the form $$\sum_{n=0}^\infty a_n\cos nx$$ but this series need not converge pointwise or uniformly to $f$ unless you have stronger assumptions on $f$. [Here you don't. A course on Fourier series may not prove this negative comment, just proving the positive comment assuming, say, that $f$ is also of bounded variation or continuously differentiable. It is essential to know why 19th century mathematicians had to fuss so much to get convergence.]
A continuous even function $f$ on $[-\pi,\pi]$ has a uniform approximation by a trigonometric polynomial of the form $$\sum_{n=0}^N a_n\cos nx$$ meaning that, for every $\epsilon>0$ you can select at least one such polynomial so that $$\left| \sum_{n=0}^N a_n\cos nx -f(x)\right| < \epsilon$$ for all $-\pi\leq x \leq \pi$. [Fejer's theorem supplies this as does the Stone-Weierstrass theorem.]
[Dangerous curve ahead!] If you change $\epsilon$ you may have to choose an entirely different polynomial, so the $a_n$ might change. Thus statement #2 does not give you a series converging to $f$, it gives you a sequence of trigonometric polynomials converging uniformly to $f$. In other words Stone-Weierstrass or Fejer's theorem does not give $$f(x)=\sum_{n=0}^\infty a_n\cos nx$$ either pointwise or uniformly. Don't write it!
If $f(x)=\sum_{i=0}^\infty f_n(x)$ on $[a,b]$ you cannot write $\int_a^b f =\sum_{i=0}^\infty \int_a^b f_n $ without claiming uniform convergence (or some more advanced property).
If $f(x)=\lim_{n\to \infty} f_n(x)$ on $[a,b]$ you can write $$\int_a^b fh =\lim_{n\to \infty} \int_a^b f_nh $$ for any continuous $h$ if you are sure you have uniform convergence (or some more advanced property).
Now we are in a position to tidy up your solution. Your ideas were fine, just missing some caution. You tried to use a series but that fails--just use a sequence instead!
For the first problem use Stone-Weierstrass to select an appropriate sequence of functions $p_n \to f$ uniformly on $[-\pi,\pi]$. Check that $$\int_{-\pi}^\pi f(x)p_n(x)\,dx =0$$ for each $n$ and that $$\lim_{n\to \infty} \int_{-\pi}^\pi f(x)p_n(x)\,dx =\int_{-\pi}^\pi [f(x)]^2\,dx.$$ Conclude that $f=0$ since it is continuous.
For the second problem use Stone-Weierstrass to select an appropriate sequence of functions $p_n \to f$ uniformly on $[0,1]$. Check that $$\int_{0}^1 f(x)p_n(x)\,dx =0$$ for each $n$ and that $$\lim_{n\to \infty} \int_{0}^1 f(x)p_n(x)\,dx =\int_{0}^1 [f(x)]^2\,dx.$$ Conclude that $f=0$ since it is continuous.