Longest rod that can be inserted within a right circular cylinder | Function to find the side of the cube ; height and radius cannot be negative ; length of rod ; Driver code
function rod ( h , r ) { if ( h < 0 && r < 0 ) return - 1 ; var l = ( Math . sqrt ( Math . pow ( h , 2 ) + 4 * Math . pow ( r , 2 ) ) ) ; return l ; } var h = 4 ; var r = 1.5 ; document . write ( rod ( h , r ) ) ;