Rectangle with minimum possible difference between the length and the width | Java implementation of the approach ; Function to print the length ( l ) and breadth ( b ) of the rectangle having area = N and | l - b | as minimum as possible ; i is a factor ; l >= sqrt ( area ) >= i ; so here l is + ve always ; Here l and b are length and breadth of the rectangle ; Driver code
class GFG { static void find_rectangle ( int area ) { int l = 0 , b = 0 ; int M = ( int ) Math . sqrt ( area ) , ans ; for ( int i = M ; i >= 1 ; i -- ) { if ( area % i == 0 ) { l = ( area / i ) ; b = i ; break ; } } System . out . println ( " l ▁ = ▁ " + l + " , ▁ b ▁ = ▁ " + b ) ; } public static void main ( String [ ] args ) { int area = 99 ; find_rectangle ( area ) ; } }