A cone has radius of $20\ \rm cm$ and a height of $40\ \rm cm$.
A cylinder fits inside the cone, as shown below.What must the radius of the cylinder be to give the cylinder the maximum volume.
You do not need to prove that the volume you have found is a maximum volume.
Show any derivatives that you need to find when solving this problem.
http://www.nzqa.govt.nz/nqfdocs/ncea-resource/exams/2014/91578-exm-2014.pdf p11 (e)
$$h=40-2r\\[5pt]\begin{align}V&=\pi r^2h\\&=\pi r^2(40-2r)\\&=40\pi r^2-2\pi r^3\end{align}\\[5pt]\frac{\mathrm dV}{\mathrm dr}=80\pi r-6\pi r^2\\\frac{\mathrm dV}{\mathrm dr}=0\implies80\pi r-6\pi r^2=0\\2\pi r(40-3r)=0\\r=\frac{40}3\text{ or }0\\r=\frac{40}3\ \mathrm{cm}$$
I was doing this calculus problem and I couldn't figure out how the answer key got $h=40-2r$. This had been bothering me for several days. Could someone please explain how the answer key got $40-2r$ for $h$?

In the picture, you can see two cones, which I will call Big Cone and Little Cone. These two cones are similar. Little Cone is a scaled down version of Big Cone.
Note that Big Cone has height $40$ and radius $20$. So the height of Big Cone is twice the radius of Big Cone.
By similarity, the height of Little Cone is twice the radius of Little Cone.
But the radius of Little Cone is $r$. So the height of Little Cone is $2r$.
It follows that the height $h$ of the cylinder is $40-2r$ (height of Big Cone minus height of Little Cone).