This question was asked in Qualcomm. without using arithmetic operations add two numbers. We can use bitwise operators to add two numbers.
#include <iostream> using namespace std; int sum(int a, int b); int main() { int a = 1, b = 0; int sum_ = 0; sum_ = sum(a, b); cout << sum_; } int sum(int x, int y) { if( x == y) return (x << 1); /*if numbers are same return 2*number*/ else return (x ^ y); } |
Shahid Siddique software engineer and WordPress adept.
He works with Cerner Corp as a Software Engineer.









stephen says:
What about 1+3?
Shahid Siddique says:
Thank you stephen for your comment. I will look into this and get back to you with the solution.
Shahid Siddique says:
So I came across one solution: http://www.daniweb.com/software-development/c/threads/84950/adding-two-numbers