<s>[INST] $\int \cos^2(x)$ by parts $$\int \cos^2(x)\ dx = \int \cos x \cos x \ dx$$
By parts, we have:
$$ \int \cos x \cos x \ dx = \cos x \sin x - \int-\sin x\ \sin x dx = \cos x \sin x + \color{Red}{\int \sin x \ \sin x \ dx}$$
but 
$$\color{Red}{\int \sin x \ \sin x \ dx} = \sin x(-\cos x)-\int\cos x \ (-\cos x) \ dx = -\sin x \ \cos x +\int \cos^2 x \ dx$$
So:
$$\int \cos^2 x \ dx = \cos x \ \sin x-\sin x \ \cos x + \int \cos^2 x dx \implies$$
$$\int \cos^2 x\ dx = 0$$
Where's the error?
 [/INST] Using integration by parts, you have
$\int\cos^2x\,dx=\cos x\sin x+\int\sin^2 x\,dx=\cos x\sin x+\int(1-\cos^2 x)\,dx=\cos x\sin x+x-\int\cos^2 x\,dx$.
Now you can solve this equation for $\int\cos^2 x\,dx$.
</s>