VOOZH about

URL: https://www.geeksforgeeks.org/dsa/implement-and-operations-using-only-arithmetic-operator/

⇱ Implement *, - and / operations using only + arithmetic operator - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Implement *, - and / operations using only + arithmetic operator

Last Updated : 23 Jul, 2025

Given two numbers, perform multiplication, subtraction, and division operations on them, using '+' arithmetic operator only.
 


Operations can be performed as follows: 

Subtraction :-  a - b = a + (-1)*b.
Multiplication :- a * b = a + a + a ... b times.
Division :- a / b = continuously subtract b from a and 
 count how many times we can do that.


The above steps look simple, but it is slightly challenging as we can't even use - to subtract. 

Output:  

Subtraction is 6
Product is -54
Division is 4

Time Complexity: O(max(|a|, |b|)), Where flipSign() function is O(|a|), sub() function is O(|b|), mul() function is O(max(|a|, |b|)) and division() function is O(|a/b|), Thus Overall, the time complexity of the code is O(max(|a|, |b|)).

Space Complexity: O(1), as it does not use any additional data structures.


Related Articles : 
 


If you like GeeksforGeeks (We know you do!) and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org.
 

Comment
Article Tags: