Check the picture below.
so, a cone inscribed in a square pyramid, like the blue one there, will have the a diameter that is the length of the base of the pyramid, as you can see there, is 6, now, since the radius is half of the diameter, that means r = 3.
we know the slant height is 9, since the slant height and the height segment make a right-triangle with the base's segment, then we use the pythagorean theorem to get the height "h".