<s>[INST] Finding maximum of a given function 
Show that $f(x)=\sin x(1+\cos x)$ attains its maximum at $x= \pi/3$.

I differentiated the function $f$ and got $f'(x)=\cos x(1+2\cos x)$. After equating with $0$, I got $x=\pi/2$ and $x =\pi/3 + n\pi$ with $n\neq 0$. So I did not get $x= \pi/3$ even as an extreme value.
 [/INST] Probably your differentiation is not correct,
$$f(x)=\sin x(1+\cos x)$$
$$f'(x)=\sin x\frac{d}{dx}(1+\cos x)+(1+\cos x)\frac{d}{dx}\sin x$$
$$=\sin x(-\sin x)+(1+\cos x)\cos x$$
$$=-\sin^2 x+\cos x+\cos^2 x$$
$$=2\cos ^2x+\cos x-1$$
$$=(2\cos x-1)(\cos x+1)$$
$$\implies f''(x)=-4\sin x\cos x-\sin-1$$
for maximum value, setting $f'(x)=0$
$$(2\cos x-1)(\cos x+1)=0$$
$$2\cos x-1=0\ \ \ \text{Or} \ \ \ \cos x+1=0$$
$$\cos x=\frac12\ \ \ \text{Or} \ \ \ \cos x=-1$$
$$\cos x=\cos \frac{\pi}{3}\ \ \ \text{Or} \ \ \ \cos x=\cos \pi$$
$$x=2n\pi\pm\frac{\pi}{3}\ \ \ \text{Or} \ \ \ \ x=2n\pi\pm\pi$$
$$x=\ldots, -\frac{5\pi}{3}, -\frac{\pi}{3}, \frac{\pi}{3}, \frac{5\pi}{3}, \ldots\ \ \ \text{Or} \ \ \ \ x=\ldots, -3\pi,-\pi, \pi, 3\pi, \ldots$$
Now, setting $x=\pi/3$ in $f''(x)$, we get
$$f\left(\frac{\pi}{3}\right)=-4\sin\frac{\pi}{3}-\sin\frac{\pi}{3}-1$$
$$\implies f\left(\frac{\pi}{3}\right)=-2\sqrt3-\frac{\sqrt3}{2}-1<0$$
hence the function $f(x)=\sin x(1+\cos x)$ is maximum at $x=\frac{\pi}{3}$
</s>