Smallest square formed with given rectangles | Recursive function to return gcd of a and b ; Everything divides 0 ; Base case ; a is greater ; Function to find the area of the smallest square ; the length or breadth or side cannot be negative ; LCM of length and breadth ; squaring to get the area ; Driver code
function gcd ( a , b ) { if ( a == 0 b == 0 ) return 0 ; if ( a == b ) return a ; if ( a > b ) return gcd ( a - b , b ) ; return gcd ( a , b - a ) ; } function squarearea ( l , b ) { if ( l < 0 b < 0 ) return - 1 ; var n = ( l * b ) / gcd ( l , b ) ; return n * n ; } var l = 6 , b = 4 ; document . write ( squarearea ( l , b ) ) ;