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
< ? php 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 ; $ n = ( $ l * $ b ) / gcd ( $ l , $ b ) ; return $ n * $ n ; } $ l = 6 ; $ b = 4 ; echo squarearea ( $ l , $ b ) . " STRNEWLINE " ; ? >