You are given two positive number n and m. You have to find simply addition of both number but with a given condition that there is not any carry system in this addition. That is no carry is added at higher MSBs.
Input : m = 456, n = 854 Output : 200 Input : m = 456, n = 4 Output : 450
To solve this problem we will need the bit by bit addition of number where we start adding two number from right most bit (LSB) and add integers from both nubers with same position. Also we will neglect carry at each position so that that carry will not affect further higher bit position.
Start adding both numbers bit by bit and for each bit take sum of integers then neglect their carry by taking modulo of bit_sum by 10 further add bit_sum to res by multiplying bit_sum with a multiplier specifying place value. (Multiplier got incremented 10 times on each iteration.)
Below is the implementation of above approach :
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- How to swap two numbers without using a temporary variable?
- Count total set bits in all numbers from 1 to n
- Add two numbers without using arithmetic operators
- Russian Peasant (Multiply two numbers using bitwise operators)
- Subtract two numbers without using arithmetic operators
- Print first n numbers with exactly two set bits
- Find Two Missing Numbers | Set 2 (XOR based solution)
- Check if a number can be expressed as a sum of consecutive numbers
- Multiplication of two numbers with shift operator
- Count smaller numbers whose XOR with n produces greater value
- Check if two numbers are equal without using arithmetic and comparison operators
- Numbers whose bitwise OR and sum with N are equal
- Count numbers whose sum with x is equal to XOR with x
- Closest (or Next) smaller and greater numbers with same number of set bits
- Check if two numbers are bit rotations of each other or not
- Find two numbers from their sum and XOR
- Check if binary representations of two numbers are anagram
- Sum of numbers with exactly 2 bits set
- 1 to n bit numbers with no consecutive 1s in binary representation.
- Check if two numbers are equal without using comparison operators
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.