Division without using ' / ' operator | Function to find division without using ' / ' operator ; Handling negative numbers ; if num1 is greater than equal to num2 subtract num2 from num1 and increase quotient by one . ; checking if neg equals to 1 then making quotient negative ; Driver program
def division ( num1 , num2 ) : NEW_LINE INDENT if ( num1 == 0 ) : return 0 NEW_LINE if ( num2 == 0 ) : return INT_MAX NEW_LINE negResult = 0 NEW_LINE if ( num1 < 0 ) : NEW_LINE INDENT num1 = - num1 NEW_LINE if ( num2 < 0 ) : NEW_LINE INDENT num2 = - num2 NEW_LINE DEDENT else : NEW_LINE INDENT negResult = true NEW_LINE DEDENT DEDENT elif ( num2 < 0 ) : NEW_LINE INDENT num2 = - num2 NEW_LINE negResult = true NEW_LINE DEDENT quotient = 0 NEW_LINE while ( num1 >= num2 ) : NEW_LINE INDENT num1 = num1 - num2 NEW_LINE quotient += 1 NEW_LINE DEDENT if ( negResult ) : NEW_LINE INDENT quotient = - quotient NEW_LINE DEDENT return quotient NEW_LINE DEDENT num1 = 13 ; num2 = 2 NEW_LINE print ( division ( num1 , num2 ) ) NEW_LINE