- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this article we will see how to add two numbers without using arithmetic operators like +, ++, -, or --.

To solve this problem, we can solve them using binary adder logic. In that case we were designed half adder and full adder. These adders can add one bit binary numbers. By cascading multiple adders, we have can create circuit to add bigger numbers.

In that adder, we have performed XOR operation among the numbers, then for the carry we were performing the ANDing logic. These features are implemented here to add two numbers.

#include <iostream> using namespace std; int add(int a, int b) { while (b != 0) { //until there is no carry, iterater int carry = a & b; //find carry by anding a and b a = a ^ b; //perform XOR on a and b, and store into a b = carry << 1; //the carry is shifted one bit to the left, and store it to b } return a; } int main() { int a, b; cout << "Enter two numbers to add: "; cin >> a >> b; cout << "The result is: " << add(a, b); return 0; }

Enter two numbers to add: 56 23 The result is: 79

- Related Questions & Answers
- Add two numbers using ++ operator in C++.
- C Program to find sum of two numbers without using any operator
- Maximum of four numbers without using conditional or bitwise operator in C++
- Find HCF of two numbers without using recursion or Euclidean algorithm in C++
- Program to find remainder without using modulo or % operator in C++
- How to sum two integers without using arithmetic operators in C/C++?
- Finding LCM of more than two (or array) numbers without using GCD in C++
- How to swap two numbers without using the third or a temporary variable using C Programming?
- 8086 program to add two 16-bit numbers with or without carry
- Modulus of two float or double numbers using C
- How to sum two integers without using arithmetic operators in C/C++ Program?
- Add two unsigned numbers using bits in C++.
- How do I overload the [] operator in C#?
- C++ program to overload addition operator to add two complex numbers
- How do I use the conditional operator in C/C++?

Advertisements