The way of solution which I followed is:
Setting $\lambda=k^2$
I get
$y'' + k^2y=0$
which gives
$y(x)=Asin(kx)+Bcos(kx)$
Taking the 1st derivative
$y'(x)=kAcos(kx)-kBsin(kx)$
I apply the BC
$y'(0)=kA=0$ and $y'(\pi)=-kA=0$
which both give $A=0$ and the solution becomes
$y(x)=Bcos(kx)$
Differentiating again
$y'(x)=-kBsin(kx)$
and applying the BC again
$y'(0)=-kBsin(0)=0$ which is true $\forall$ k
and
$y'(\pi)=-kBsin(k\pi)=0$ which must give
$sin(k\pi)=0\Rightarrow k\pi=n\pi\Rightarrow k=n$
so the eigenfunctions are
$y_n(x)=Bcos(nx)$ for $n=\pm1,\pm2,\pm3...$
Can somebody please ensure that this way is right? Should or should not $x$ be a part of eigenfunction formula?