Minimum and maximum possible length of the third side of a triangle | Function to find the minimum and the maximum possible length of the third side of the given triangle ; Not a valid triangle ; Not a valid triangle ; Driver code
function find_length ( s1 , s2 ) { if ( s1 <= 0 s2 <= 0 ) { document . write ( - 1 ) ; return ; } var max_length = s1 + s2 - 1 ; var min_length = Math . max ( s1 , s2 ) - Math . min ( s1 , s2 ) + 1 ; if ( min_length > max_length ) { document . write ( - 1 ) ; return ; } document . write ( " " + max_length + " " ) ; document . write ( " " + min_length ) ; } var s1 = 8 , s2 = 5 ; find_length ( s1 , s2 ) ;