- 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

# How do I add two numbers without using ++ or + or any other arithmetic operator in C/C++?

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.

## Example Code

#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; }

## Output

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

- Related Questions & Answers
- C Program to find sum of two numbers without using any operator
- Add two numbers using ++ operator in C++.
- Maximum of four numbers without using conditional or bitwise operator in C++
- 8086 program to add two 16-bit numbers with or without carry
- 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 swap two numbers without using the third or a temporary variable using C Programming?
- Finding LCM of more than two (or array) numbers without using GCD in C++
- How to sum two integers without using arithmetic operators in C/C++?
- Modulus of two float or double numbers using C
- How to sum two integers without using arithmetic operators in C/C++ Program?
- How do I run two or more functions when using 'onclick' JavaScript?
- How do I check if a string has alphabets or numbers in Python?
- 8085 program to subtract two 8-bit numbers with or without borrow
- 8086 program to subtract two 16-bit numbers with or without borrow

Advertisements