- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 to sum two integers without using arithmetic operators in C/C++?
The following is an example to add two numbers without using arithmetic operators.
Example
#include <iostream> #include <cmath> using namespace std; int add(int val1, int val2) { while(val2 != 0) { int c = val1 & val2; val1 = val1 ^ val2; val2 = c << 1; } return val1; } int main() { cout <<"The sum of two numbers : "<< add(28, 8); return 0; }
Output
The sum of two numbers : 36
In the above program, a function add() is defined with two int type arguments. The addition of two numbers is coded in add()
int add(int val1, int val2) { while(val2 != 0) { int c = val1 & val2; val1 = val1 ^ val2; val2 = c << 1; } return val1; }
In the main() function, the result is printed by calling function add()
cout <<"The sum of two numbers : "<< add(28, 8);
- Related Articles
- How to sum two integers without using arithmetic operators in C/C++ Program?
- Arithmetic Operators in C++
- How do I add two numbers without using ++ or + or any other arithmetic operator in C/C++?
- What are arithmetic operators in C#?
- Simple Arithmetic Operators Example Program In C++
- Sum of array using pointer arithmetic in C++
- Sum of array using pointer arithmetic in C
- How to get the product of two integers without using * JavaScript
- C Program to find sum of two numbers without using any operator
- Find maximum in an array without using Relational Operators in C++
- Find minimum in an array without using Relational Operators in C++
- Explain the concept of Arithmetic operators in C language
- Check if n is divisible by power of 2 without using arithmetic operators in Python
- Multiply a number by 15 without using * and / operators in C++
- Find the Sum of two Binary Numbers without using a method in C#?

Advertisements