Area of plot remaining at the end | Function to return the area of the remaining plot ; Continue while plot has positive area and there are persons left ; If length > breadth then subtract breadth from length ; Else subtract length from breadth ; Driver code
function remainingArea ( N , M , K ) { while ( K -- && N && M ) { if ( N > M ) N = N - M ; else M = M - N ; } if ( N > 0 && M > 0 ) return N * M ; else return 0 ; } var N = 5 , M = 3 , K = 2 ; document . write ( remainingArea ( N , M , K ) ) ;