Area of a largest square fit in a right angle triangle | Function to find the area of the biggest square ; the height or base or hypotenuse cannot be negative ; side of the square ; squaring to get the area ; Driver code
function squareArea ( l , b , h ) { if ( l < 0 b < 0 h < 0 ) return - 1 ; var a = ( l * b ) / ( l + b ) ; return a * a ; } var l = 5 , b = 12 , h = 13 ; document . write ( squareArea ( l , b , h ) . toFixed ( 4 ) ) ;