# Division without using ‘/’ operator

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
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

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 substraction 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 ` `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

 `= ``\$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 ` `?> `

Output :

```6
```

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Improved By : nitin mittal, jit_t

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.
{"ft_lang_label":"__label__en","ft_lang_prob":0.5550773,"math_prob":0.9885543,"size":6430,"snap":"2019-51-2020-05","text_gpt3_token_len":1997,"char_repetition_ratio":0.17226891,"word_repetition_ratio":0.3992126,"special_character_ratio":0.3415241,"punctuation_ratio":0.13619745,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9998846,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-24T03:18:31Z\",\"WARC-Record-ID\":\"<urn:uuid:050548ef-bf00-4c1a-bac6-c26bbcbd1dfb>\",\"Content-Length\":\"182185\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9106cf38-6a23-4036-8cfb-56c3bc5df1d1>\",\"WARC-Concurrent-To\":\"<urn:uuid:a4a63c13-8418-48c3-9adc-6bdeb10ac83b>\",\"WARC-IP-Address\":\"204.237.142.232\",\"WARC-Target-URI\":\"https://www.geeksforgeeks.org/division-without-using-operator/\",\"WARC-Payload-Digest\":\"sha1:PN7C24HMCG3W4VAMYV4MRZZEPDWDTWCJ\",\"WARC-Block-Digest\":\"sha1:QYSIYZVJ5UD24CLXYTZVNGIC56FZQKKF\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579250614880.58_warc_CC-MAIN-20200124011048-20200124040048-00504.warc.gz\"}"}