Largest cube that can be inscribed within the sphere | Function to find the side of the cube ; radius cannot be negative ; side of the cube ; Driver code
function largestCube ( r ) { if ( r < 0 ) return - 1 ; var a = ( 2 * r ) / Math . sqrt ( 3 ) ; return a ; } var r = 5 ; document . write ( largestCube ( r ) . toFixed ( 5 ) ) ;