Largest cube that can be inscribed within a right circular cone | Function to find the side of the cube ; height and radius cannot be negative ; side of the cube ; Driver code
function cube ( h , r ) { if ( h < 0 && r < 0 ) return - 1 ; var a = ( h * r * Math . sqrt ( 2 ) ) / ( h + Math . sqrt ( 2 ) * r ) ; return a ; } var h = 5 , r = 6 ; document . write ( cube ( h , r ) . toFixed ( 5 ) ) ;