Add two numbers without using addition operator | 5 methods

Given two numbers, add them without using addition operator.



Method 1: Use subtraction operator



Method 2: Repeated Addition/Subtraction using –/++ operator


Download   Run Code


13 -3 3


Method 3: Using printf()


This method make use of two facts –
1. We can use an asterisk (*) to pass the width precision to printf(), rather than hard coding it into the format string
2. printf() function return the number of characters printed on output stream.

We can also use %*c, ‘ ‘ in place of %*s, “”.


Method 4: Half adder logic



Method 5: Using logarithm and exponential function



1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)


Thanks for reading.

Please use our online compiler to post code in comments. To contribute, get in touch with us.
Like us? Please spread the word and help us grow. Happy coding 🙂

Leave a Reply

newest oldest most voted
Notify of
Daniel Sigurdsson

You have one more:


Method3 using negative will get wrong result.
eg. a=-3,b=4,the code will return7