File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Python3 program to divide a number
2
+ # by other without using / operator
3
+
4
+ # Function to find division without
5
+ # using '/' operator
6
+ def division(num1, num2):
7
+
8
+ if (num1 == 0): return 0
9
+ if (num2 == 0): return INT_MAX
10
+
11
+ negResult = 0
12
+
13
+ # Handling negative numbers
14
+ if (num1 < 0):
15
+ num1 = - num1
16
+
17
+ if (num2 < 0):
18
+ num2 = - num2
19
+ else:
20
+ negResult = true
21
+
22
+ elif (num2 < 0):
23
+ num2 = - num2
24
+ negResult = true
25
+
26
+ # if num1 is greater than equal to num2
27
+ # subtract num2 from num1 and increase
28
+ # quotient by one.
29
+ quotient = 0
30
+
31
+ while (num1 >= num2):
32
+ num1 = num1 - num2
33
+ quotient += 1
34
+
35
+ # checking if neg equals to 1 then
36
+ # making quotient negative
37
+ if (negResult):
38
+ quotient = - quotient
39
+ return quotient
40
+
41
+ # Driver program
42
+ num1 = 13; num2 = 2
43
+ print(division(num1, num2))
44
+
45
+
You can’t perform that action at this time.
0 commit comments