Find Quotient and Remainder of two integer without using division operators | Function to the quotient and remainder ; Check if start is greater than the end ; Calculate mid ; Check if n is greater than divisor then increment the mid by 1 ; Check if n is less than 0 then decrement the mid by 1 ; Check if n equals to divisor ; Return the final answer ; Recursive calls ; Driver code
function find ( dividend , divisor , start , end ) { if ( start > end ) return [ 0 , dividend ] ; var mid = start + parseInt ( ( end - start ) / 2 ) ; var n = dividend - divisor * mid ; if ( n > divisor ) start = mid + 1 ; else if ( n < 0 ) end = mid - 1 ; else { if ( n == divisor ) { ++ mid ; n = 0 ; } return [ mid , n ] ; } return find ( dividend , divisor , start , end ) ; } function divide ( dividend , divisor ) { return find ( dividend , divisor , 1 , dividend ) ; } var dividend = 10 , divisor = 3 ; var ans = divide ( dividend , divisor ) ; document . write ( ans [ 0 ] + " " ) ; document . write ( ans [ 1 ] + " " ) ;