Division without using '/' operator Last Updated : 20 Feb, 2023 Comments Improve Suggest changes Like Article Like Report Given two numbers, divide one from other without using '/' operator. Examples : Input : num1 = 13, num2 = 2 Output : 6 Input : num1 = 14, num2 = -2 Output : -7 Input : num1 = -11, num2 = 3 Output : -3 Input : num1 = 10, num2 = 10 Output : 1 Input : num1 = -6, num2 = -2 Output : 3 Input : num1 = 0, num2 = 5 Output : 0 In order to perform division operation without using '/' operator we followed the approach, in which we count the number of successful or complete number of subtraction of num2 from num1. Where num1 is the number to be divided and num2 is the number from which we have to divide num1. C++ // CPP program to divide a number by other // without using / operator #include <bits/stdc++.h> using namespace std; // Function to find division without using // '/' operator int division(int num1, int num2) { if (num1 == 0) return 0; if (num2 == 0) return INT_MAX; bool negResult = false; // Handling negative numbers if (num1 < 0) { num1 = -num1 ; if (num2 < 0) num2 = - num2 ; else negResult = true; } else if (num2 < 0) { num2 = - num2 ; negResult = true; } // if num1 is greater than equal to num2 // subtract num2 from num1 and increase // quotient by one. int quotient = 0; while (num1 >= num2) { num1 = num1 - num2 ; quotient++ ; } // checking if neg equals to 1 then making // quotient negative if (negResult) quotient = - quotient ; return quotient ; } // Driver program int main() { int num1 = 13, num2 = 2 ; cout << division(num1, num2); ; return 0; } Java // Java program to divide a number by other // without using / operator import java.io.*; class GFG { // Function to find division without using // '/' operator static int division(int num1, int num2) { if (num1 == 0) return 0; if (num2 == 0) return Integer.MAX_VALUE; boolean negResult = false; // Handling negative numbers if (num1 < 0) { num1 = -num1 ; if (num2 < 0) num2 = - num2 ; else negResult = true; } else if (num2 < 0) { num2 = - num2 ; negResult = true; } // if num1 is greater than equal to num2 // subtract num2 from num1 and increase // quotient by one. int quotient = 0; while (num1 >= num2) { num1 = num1 - num2 ; quotient++ ; } // checking if neg equals to 1 then making // quotient negative if (negResult) quotient = - quotient ; return quotient ; } // Driver program public static void main (String[] args) { int num1 = 13, num2 = 2 ; System.out.println( division(num1, num2)); } } // This code is contributed by vt_m. Python3 # Python3 program to divide a number # by other without using / operator # Function to find division without # using '/' operator def division(num1, num2): if (num1 == 0): return 0 if (num2 == 0): return INT_MAX negResult = 0 # Handling negative numbers if (num1 < 0): num1 = - num1 if (num2 < 0): num2 = - num2 else: negResult = true elif (num2 < 0): num2 = - num2 negResult = true # if num1 is greater than equal to num2 # subtract num2 from num1 and increase # quotient by one. quotient = 0 while (num1 >= num2): num1 = num1 - num2 quotient += 1 # checking if neg equals to 1 then # making quotient negative if (negResult): quotient = - quotient return quotient # Driver program num1 = 13; num2 = 2 print(division(num1, num2)) # This code is contributed by Ajit. C# // C# program to divide a number by other // without using / operator using System; class GFG { // Function to find division without // using '/' operator static int division(int num1, int num2) { if (num1 == 0) return 0; if (num2 == 0) return int.MaxValue; bool negResult = false; // Handling negative numbers if (num1 < 0) { num1 = -num1 ; if (num2 < 0) num2 = - num2 ; else negResult = true; } else if (num2 < 0) { num2 = - num2 ; negResult = true; } // if num1 is greater than equal to num2 // subtract num2 from num1 and increase // quotient by one. int quotient = 0; while (num1 >= num2) { num1 = num1 - num2 ; quotient++ ; } // checking if neg equals to 1 then making // quotient negative if (negResult) quotient = - quotient ; return quotient ; } // Driver Code public static void Main () { int num1 = 13, num2 = 2 ; Console.Write( division(num1, num2)); } } // This code is contributed by nitin mittal. PHP <?php // CPP program to divide a number by other // without using / operator // Function to find division without using // '/' operator function division($num1, $num2) { if ($num1 == 0) return 0; if ($num2 == 0) return INT_MAX; $negResult = false; // Handling negative numbers if ($num1 < 0) { $num1 = -$num1 ; if ($num2 < 0) $num2 = - $num2 ; else $negResult = true; } else if ($num2 < 0) { $num2 = - $num2 ; $negResult = true; } // if num1 is greater than equal to num2 // subtract num2 from num1 and increase // quotient by one. $quotient = 0; while ($num1 >= $num2) { $num1 = $num1 - $num2 ; $quotient++ ; } // checking if neg equals to 1 then making // quotient negative if ($negResult) $quotient = - $quotient ; return $quotient ; } // Driver program $num1 = 13; $num2 = 2 ; echo division($num1, $num2) ; // This code is contributed by ajit ?> JavaScript <script> // Javascript program to divide a number by other // without using / operator // Function to find division without using // '/' operator function division( num1, num2) { if (num1 == 0) return 0; if (num2 == 0) return Number.MAX_VALUE;; let negResult = false; // Handling negative numbers if (num1 < 0) { num1 = -num1; if (num2 < 0) num2 = -num2; else negResult = true; } else if (num2 < 0) { num2 = -num2; negResult = true; } // if num1 is greater than equal to num2 // subtract num2 from num1 and increase // quotient by one. let quotient = 0; while (num1 >= num2) { num1 = num1 - num2; quotient++; } // checking if neg equals to 1 then making // quotient negative if (negResult) quotient = -quotient; return quotient; } // Driver program let num1 = 13, num2 = 2; document.write(division(num1, num2)); // This code is contributed by gauravrajput1 </script> Output6 Time Complexity: O(num1/num2)Auxiliary Space: O(1), As constant extra space is used. Comment More infoAdvertise with us Next Article Division without using '/' operator N nikunj_agarwal Follow Improve Article Tags : Misc Mathematical DSA Basic Coding Problems Practice Tags : MathematicalMisc Similar Reads Divide two integers without using multiplication and division operator Given two integers a and b, the task is to find the quotient after dividing a by b without using multiplication, division, and mod operator.Note: If the quotient is strictly greater than 231 - 1, return 231 - 1 and if the quotient is strictly less than -231, then return -231.Examples: Input : a = 10 10 min read Find Quotient and Remainder of two integer without using division operators Given two positive integers dividend and divisor, our task is to find quotient and remainder. The use of division or mod operator is not allowed. Examples: Input : dividend = 10, divisor = 3 Output : 3, 1 Explanation: The quotient when 10 is divided by 3 is 3 and the remainder is 1. Input : dividend 10 min read Divide two number using Binary search without using any / and % operator Given two integers one is a dividend and the other is the divisor, we need to find the quotient when the dividend is divided by the divisor without the use of any " / " and " % " operators. Examples:Input: dividend = 10, divisor = 2Output: 5Explanation: 10/2 = 5.Input: dividend = 10, divisor = 3Outp 6 min read Divide two integers without using multiplication, division and mod operator | Set2 Given two integers say a and b. Find the quotient after dividing a by b without using multiplication, division and mod operator.Examples: Input: a = 10, b = 3Output: 3 Input: a = 43, b = -8Output: -5 This problem has been already discussed here. In this post, a different approach is discussed.Approa 7 min read Find ceil of a/b without using ceil() function Given a and b, find the ceiling value of a/b without using ceiling function. Examples: Input: a = 5, b = 4 Output: 2 Explanation: a/b = ceil(5/4) = 2 Input: a = 10, b = 2Output: 5 Explanation: a/b = ceil(10/2) = 5 The problem can be solved using the ceiling function, but the ceiling function does no 8 min read Program to find remainder without using modulo or % operator Given two numbers 'num' and 'divisor', find remainder when 'num' is divided by 'divisor'. The use of modulo or % operator is not allowed.Examples : Input: num = 100, divisor = 7 Output: 2 Input: num = 30, divisor = 9 Output: 3 Method 1 : C++ // C++ program to find remainder without using // modulo o 9 min read Non-Restoring Division For Unsigned Integer The non-restoring division is a division technique for unsigned binary values that simplifies the procedure by eliminating the restoring phase. The non-restoring division is simpler and more effective than restoring division since it just employs addition and subtraction operations instead of restor 4 min read Modular Division Modular division is the process of dividing one number by another in modular arithmetic. In modular arithmetic, division is defined differently from regular arithmetic because there is no direct "division" operation. Instead, modular division involves multiplying by the modular multiplicative invers 10 min read Restoring Division Algorithm For Unsigned Integer The Restoring Division Algorithm is an integral procedure employed when calculating division on unsigned numbers. It is particularly beneficial in the digital computing application whereby base-two arithmetic is discrete. As a distinct from other algorithms, the Restoring Division Algorithm divides 5 min read Fraction to Recurring Decimal Given two integers a and b(b != 0), the task is to return the fraction a/b in string format. If the fractional part is repeating, enclose the repeating part in parentheses.Examples: Input: a = 1, b = 2Output: "0.5"Explanation: 1/2 = 0.5 with no repeating part.Input: a = 50, b = 22Output: "2.(27)"Exp 8 min read Like